Asynchronous interface in java

I am working on a Java program, and it has been more than a year since I used Java, so I'm a little rusty. This program uses Runtime.exec()to call other programs to perform its dirty work and must independently analyze their output data and update their own graphical interface in real time while other programs are working. What is the best way to do this? Currently, I am thinking that my class of external executing program has its own internal thread, which polls the output of the external program, and then raises events when noticeable events occur, and then implements my own interfaceEventListenerfor my user interface classes. However, I am worried about how this will handle the asynchronous nature of the triggered events. Can anyone give any advice on how to protect listeners from race conditions and / or a better approach? Thank.

+3
source share
1 answer
  • You do not need a poll for output in an external process. The object Processreturned from Runtime.exec(String)has methods for getting InputStreamfor stderr and stdout and for OutputStreamfor stdin.
  • You can chat by sending messages via OutputStream. Just enter the data into the stream.
  • a Thread, stdout OutputStream. , , .
  • Event Dispatcher Thread, EDT. Swing/AWT, .
  • stdin. EventListener, . (, ) OutputStream .

.

+2

Source: https://habr.com/ru/post/1753058/


All Articles