JavaFX Threading

Kevin Rushforth kevin.rushforth at
Wed Mar 6 17:03:15 PST 2013

Does anyone think we shouldn't make this change? While it is a 
behavioral change, I doubt it will cause problems for applications. On 
the contrary, naive applications will be less likely to run into 
problems after this change. Sophisticated applications can still do 
background loading in the init() method for long-running initialization.

One slight correction to what Steve wrote:

> What about application construction?
> Today, this is unspecified ...

Actually, this is specified today. The javadoc for the Application class 
says this:

 * The Application constructor and {@code init} method are called on
 * the launcher thread, not on the JavaFX Application Thread.
 * This means that an application must not construct a {@link Scene}
 * or a {@link Stage} in either the constructor or in the {@code init}
 * method.

So we will need to change the docs as part of this JIRA.

-- Kevin

steve.x.northover at wrote:
> Hi all,
> One of the great things about JavaFX is that it has a consistent 
> threading model that maps well on to the underlying platforms.  There 
> is a single distinguished GUI-thread that is also the GUI-thread for 
> the window system.  This makes JavaFX GUI behavior consistent and 
> deterministic.  In general, running code in the GUI thread is a good 
> thing for these reasons and others, provided that the code is not long 
> running.  In the case of long running code, JavaFX objects may be 
> created in background threads as long are they are not attached to the 
> scene graph.
> JavaFX applications have a life cycle that includes, construction, 
> init(), start() and stop().  The start() method is the most important 
> and runs in the GUI-thread.  The init() method is guaranteed to run in 
> a background thread and is the place where long running creation code 
> can reside.  The start() method will always run after init() has 
> completed.  With a preloader, the start() of the preloader runs at the 
> same time as the init() of the application.  The stop() method is also 
> guaranteed to run in the GUI-thread.
> What about application construction?
> Today, this is unspecified and happens in a background thread.  We are 
> considering moving this to the GUI-thread.  Here is the JIRA that is 
> tracking this work:
> If you are interested, add yourself, please add yourself to it and 
> comment either there or on this list,
> Thanks!
> Steve

More information about the openjfx-dev mailing list