0 Replies - 9790 Views - Last Post: 20 January 2013 - 11:50 PM

#1 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon

Reputation: 12316
  • View blog
  • Posts: 45,416
  • Joined: 27-December 08

[Link] JavaFX Series- Threading Issues

Posted 20 January 2013 - 11:50 PM


Because the call to add a new object came from a thread started by a business class, it can not get directly processed. This would cause the following exception:

Exception in thread "Timer-1" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-1

This is the reason why the whole body of the method is wrapped in Platform.runLater(). Quoting from the API doc, this method runs the specified Runnable on the JavaFX Application Thread at some unspecified time in the future. This method, which may be called from any thread, will post the Runnable to an event queue and then return immediately to the caller. The Runnables are executed in the order they are posted.

This method allows for a complete separation of the UI and the business logic. Before reading about this method here, I thought that every call to a JavaFX component has to come directly from the FX application thread. That would have broken my architecture and my separations of concerns.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1