JavaFX app with Spring doesn't terminate on Mac OS X with Cmd-Q
anthony.petrov at oracle.com
Fri Jul 5 03:46:35 PDT 2013
Cmd-Q (or, rather the implicit exit machinery) does not call
System.exit(). All it does when it detects that there's no FX windows
open, it terminates the FX Event Thread. This is clearly stated in the
The rest depends on the JVM. As long as there are active non-daemon
threads running, the JVM won't exit. I suspect that the services you're
running create non-daemon threads and they prevent the JVM from exiting.
So the solution you came up with (calling applicationContext.close())
looks correct: you tell the background services to shut down, and then
the application can terminate as expected.
Hope this helps.
On 07/04/2013 10:15 PM, Fabrizio Giudici wrote:
> I have a JavaFX app that uses Spring to instantiate a number of services
> and presentation controllers. I think it's relevant to mention that
> among other services there's Jetty, an embedded web server that starts
> listening to a socket with its own threads. The Spring
> ApplicationContext is initialized in background after init() is called;
> and it also uses applicationContext.registerShutdownHook(). When I run
> the application in development mode (with Maven, from the terminal) or I
> launch the Java stub inside the bundled .app from the terminal (so the
> process is bound to the terminal) and I hit Ctrl-C, the application
> properly quits (with the Spring Application Context properly shutting
> down everything). When I launch the bundled .app and I press Cmd-Q, the
> window closes, but the application lingers somewhere (e.g. I see it in
> running processes). I have to "force quit" it.
> Platform.setImplicitExit(true) doesn't make any difference.
> I expected that Cmd-Q called System.exit() and the Spring
> ApplicationContext just had its opportunity to orderly quit thanks to
> the shutdown hook. Instead, I see that the ApplicationContext stays
> alive and probably the threads started by some services keep the
> application running.
> I've found that this solution works:
> stage.setOnCloseRequest(new EventHandler<WindowEvent>()
> public void handle (final @Nonnull WindowEvent event)
> For me it's fine, but I'd like to understand whether this is the correct
> behaviour, or I'm doing something wrong, or there's a bug somewhere.
> Details: JDK 1.7.0_25 with its embedded JavaFX runtime, Mac OS X 10.8.4.
> Sources fully available if needed.
More information about the openjfx-dev