JavaFX app with Spring doesn't terminate on Mac OS X with Cmd-Q

Fabrizio Giudici Fabrizio.Giudici at
Thu Jul 4 11:15:25 PDT 2013


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  

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.


Fabrizio Giudici - Java Architect @ Tidalwave s.a.s.
"We make Java work. Everywhere." - fabrizio.giudici at

More information about the openjfx-dev mailing list