Transmit Strings to Main thread from Background thread

65 Views Asked by At

I need to transmit Strings to Main thread (there is GUI) to add them to javafx' TextFlow.

In the background thread's run(), reader waits strings from JSch channel. On new stings it must transmit them to main thread. So main thread can't wait data from background thread (as it is GUI thread), and background thread must send some event with new Strings.

Another trouble, that in application can be, for example, 4 background threads, that reads some data from JSch channel and send it to one window to show.

1

There are 1 best solutions below

2
On

To transmit data to the GUI thread,use Platfotm.runLater() method

Platform.runLater(() -> {
        /*send your data from here*/
    });

Platform.runLater makes you modify the GUI thread from other threads, It has a swing equivalent of SwingUtilities.invokeLater