Platform.runLater and Task in JavaFX

前端 未结 4 611
孤独总比滥情好
孤独总比滥情好 2020-11-22 08:54

I have been doing some research on this but I am still VERY confused to say the least.

Can anyone give me a concrete example of when to use Task and whe

4条回答
  •  旧巷少年郎
    2020-11-22 09:30

    • Platform.runLater: If you need to update a GUI component from a non-GUI thread, you can use that to put your update in a queue and it will be handled by the GUI thread as soon as possible.
    • Task implements the Worker interface which is used when you need to run a long task outside the GUI thread (to avoid freezing your application) but still need to interact with the GUI at some stage.

    If you are familiar with Swing, the former is equivalent to SwingUtilities.invokeLater and the latter to the concept of SwingWorker.

    The javadoc of Task gives many examples which should clarify how they can be used. You can also refer to the tutorial on concurrency.

提交回复
热议问题