I have a JavaFX application that runs multiple threads that do heavy computing. The problem is that after a while the UI completely freezes, but I only update the UI with Platform.runLater()
The way I start my main thread that spawns the rest of the threads:
mainThread = new MainThread(mc);
mainThread.start();
Here I give the thread the reference to the main Controller, which passes this reference to the rest of the threads so they can print stuff to a TextArea.
The main thread spawns only 2 sub-threads at once, but these two sub-threads use ExecutorService with configurable number of threads(100+):
executor = Executors.newFixedThreadPool((Integer.valueOf(mainController.getIndexController().getThreadsField().getText())));
for(int i = 0; i < newTasks.size(); i++){
Runnable slaveThread = new SlaveThread(dataLink, url);
executor.execute(slaveThread );
}
Now threads do lots of stuff like downloading files, but I guess that should not affect the UI. They occasionally read from the interface, but that shouldn't be the problem.
I thought that by using platform.runlater(), the UI can't be frozen.
Platform.runLater(() -> {
mainController.getIndexController().writeToConsole(result);
});
Since I don't have any other code that modifies the UI, this must be the problem. The program executes many-many Platform.runLater()-s, is it too much? Or how much is too much? There are other applications with smooth UI that update the interface way more frequently than mine and run just fine. What can be the problem? Thanks.