System freezes when trying to run external command from Java with wait for

Apotekarnes

Mitglied
Hello everybody,

from my JAVA GUI I want to run a Python script.

When I do it with Runtime.exec(), everything is fine, except the GUI doesn't wait for the external process to end. So I had to switch to ProcessBuilder/SystemCommandExecutor and similar solutions as System.out.println(p.waitFor() == 0).

All of the latter solutions cause my whole System to freeze immediately as soon as the external Process is launched - I have to reboot 🙁

In the SystemMonitor of Ubuntu I could see the Memory consumption by this Python Script rising and rising, while I could not click anything.

When the Python script is run independently from my GUI OR with Runtime.exec(), memory consumption is mid-high, but the system does not freeze.

What can I do?

Best regards
Apotekarnes
 
Ok, I found out, the "system freezes" are not due to RAM problems but caused by the ActionListener waiting for my Python process to end.

RAM consumption is high, but after a few minutes, the Button belonging to the ActionListener is released and I can interfere with my Operating System again.

The question now is:
- Why does a JAVA GUI ActionListener block the access of whole Ubuntu?
- If this behavior is not changeable, can I somehow start a new thread for the ActionListener to make the rest of my GUI and hopefully my OS accessible while KEEPING the Process.waitFor() in the ActionListener?

Best regards
Apotekarnes
 
Uhm, this forum is German.
I speak fluent English, but most of the other people probably don't.
You should at least try to translate your questions to German, so that the people who an help you can understand your question easier, rather than translating everything bit by bit 🙂
 
Hi,

execution of an action listener is done in the EDT Thread. This Thread is responsible for drawing the gui as it change.

If you start an external action within the edt Thread it blocks your gui, becouse no other action can be proccessed.

The reason why your system freeze is, that your external application trys to print information to the stdout. You are not reading this information thus this buffer continues to fill. You ram is beeing consumed.

You have to start an seperate Thread and read the OutputStream from the process.

Hope this helps .

Best regards
 

Neue Themen


Zurück
Oben