Platform dependent behavior in Platform.startup()

Johan Vos johan.vos at gluonhq.com
Wed Jul 31 09:24:42 UTC 2019


Hi,

A pattern I increasingly use is to add JavaFX functionality to existing
non-JavaFX applications. Rather than adding a class that extends
javafx.application.Application, I add some code to an existing class, like
this:

javafx.platform.Platform.startup(() -> {System.err.println("JavaFX
started");});
javafx.platform.Platform.runLater(() -> {Stage, Scene,... });

I noticed that having Platform.startup() in a class initialiser works fine
on Linux/Windows, but fails on Mac when a lambda is passed to startup().

The reason for this is that on Mac, the main thread that starts Glass
blocks until Glass has been started.
But starting Glass also contains running the argument passed to startup().
In case this is a lambda, this requires the encapsulating class to be
initialized -- but initializing this class is happening already but blocked
on Glass being started.

The other platforms (Windows/Linux) are less strict. They don't block on
Glass being started (including running the Runnable passed to startup)
before they return.

I created issue https://github.com/javafxports/openjdk-jfx/issues/542 for
this and I propose to fix it via PR
https://github.com/javafxports/openjdk-jfx/pull/543 which considers Glass
to be started *before* the supplied runnable is executed.

- Johan


More information about the openjfx-dev mailing list