Multithreading in JavaFX hangs the UI

后端 未结 1 867
野性不改
野性不改 2020-12-08 20:30

I have a simple JavaFX 2 app, with 2 buttons, saying Start and Stop. When the start button is clicked, I want to create a background thread which will do some processing and

相关标签:
1条回答
  • 2020-12-08 21:11

    Task implements Runnable, so when you call handler.run(); you actually run the call method in the UI Thread. That will hang the UI.

    You should start the task in a background thread, either via an executor or simply by calling new Thread(handler).start();.

    This is explained (maybe not very clearly) in the javadoc or in the JavaFX concurrency tutorial.

    0 讨论(0)
提交回复
热议问题