JavaFX Task/Service thread checks

Richard Bair richard.bair at
Tue Jun 12 12:50:42 PDT 2012

> Could you explain what the issues are when different Threads have listeners attached to a Task's stateProperty?  AFAIK, all the listeners get fired (one by one) on the fx thread, not on the thread that attached the listener in the first place.

I think that is the main thing. You end up adding a listener from some thread, but then that listener is called back on the FX thread, which may be surprising. Rather, we force you to face the fact that it is going to be on a different thread.

> I can understand that a method like setState() (if it existed) must be called from the fx-thread, as that could cause listeners to fire (which must be on the fx thread afaik)... but attaching a listener should be possible from any thread (barring issues with managing and traversing the listener list itself -- those would need synchronization) ...... I guess that last one probably touches upon why this thread check is there as the other thread would be holding a lock preventing the fx-thread from proceeding -- although such a lock would never be held for long...

That as well, that the code is simpler without it. But that isn't sufficient reason in and off itself (adding synchronized is easy enough).


More information about the openjfx-dev mailing list