↓ Skip to main content

The FX Application Thread

All of the JavaFX Nodes and Observables are not thread safe. Instead JavaFX provides a dedicated thread called the “FX Application Thread” or “FXAT” which needs to be used whenever you update any of these objects.

This is probably the subject that trips up beginners the most. Not that you have to use the FXAT for updates, but that you should never use the FXAT for long or blocking jobs. This can be easy to skip, because development and testing environments often do not have real domain setups that actually respond in the same time frames as live environments. The result is that everything works fine until you release your application, then it flops in production.

The good news is that JavaFX provides a tool to deal with all of this: Task. Essentially, Task is an abstract class that implements Runnable and Future<V>, which means that you can instantiate an anonymous inner class based on it and pass it to the constructor of Thread. Then you can call whatever code you’ve configured the Task to run through Thread.start() which, by definition, is running off the FXAT.

On top of that, Task contains all of the tools that you need to connect it back to the FXAT. You can monitor progress while the Task is running from the FXAT, and you can specify code to run on the FXAT when the Task completes.

Everything You Really Need to Know About the FXAT

19 mins
“Hey, you jobs! Get off my FXAT!” Learn how to deal with the JavaFX Application Thread - How to get your background jobs onto their own threads the right way, and how process the results back on the FXAT.

Tracking Task Progress

18 mins
A deeper look at the Task class and how to monitor progress while a Task in running on a background thread.

Task Partial Results: Lists

28 mins
What if you want to monitor the progress of a Task that is collecting data into a List? This article shows an approach to handling accumulated data in on ObserableList while a Task is running while still playing nicely with the FXAT.