JavaFX Async Task

Today someone asked how to use the javafx.async package. The javafx.async package is useful if you have some background work to do that you don’t want to run on the main JavaFX thread. Perhaps you are doing some serious number crunching, or maybe some file IO and if you did this on the main thread, the user would be blocked from doing anything and features like animation would scream to a halt. To illustrate how to use the async package, here is a trivial implementation that merely spawns a task that sleeps 5 seconds. Right before the sleep starts and right after the sleep ends, a message is sent back to the JavaFX main routine and displayed on the screen.

Go to Source

Leave a Reply

You must be logged in to post a comment.