I have an application which I launch from the command line (MacOS). I have added a shutdown hook to my initial code so that it closes down gracefully.
The entry point for the application is non visual and runs in a terminal window. If I close terminal by either using the (red) button on the terminal window - or use the pull down menu for the active application title bar then my shutdown hook code is triggered and the application shuts down cleanly.
So - now for the tricky bit to explain. My terminal window which is running creates a number of JFrames which I display real time information in. If one of these windows has focus then the Mac title bar changes from showing Terminal to the name of the initial Class name of my GUI. I suppose that's reasonable.
However if I now use that new title bar at the top of MacOS and select Quit for the GUI component then my shutdown hook does not get called and in fact I have to forcibly terminate the application.
I doubt it's the case but it almost appears that the startup code running in the terminal window is using one JVM and the GUI code is running another JVM - the later not having a shutdown hook.
I appreciate this probably not a good explanation and might be mac specific.
I have added 2 screen dumps.