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'm afraid your screen dumps didn't make the trip.
Although parts of what you're describing sound like how the original MacOS handled title bars - which differed from other GUIs - I think your real problem is not really MacOS related.
A Java application does not truly terminate - that is, the JVM does not exit - until all threads in the JVM have terminated. As long as even one thread lives, the JVM shutdown will hang.
There are quite a few threads running in your average JVM, but most of them (stuff like the garbage collector) understand when shutdown has been signalled and they then terminate themselves. That includes, in the case of a GUI system like Swing, the rendering and UI threads.
So killing just one window by brute force might not be enough. Ideally you should have an "Exit" command action (tied to things like the File/Exit menu) that will initiate a clean shutdown, but if you should kill processes relating to just one window, for example, then something like what you seem to be describing would apply - the remaining threads would hang the JVM shutdown process.
Note that doing an OS-level termination ("Force close/quit" for desktops that support it or a "kill" from command line) terminate the JVM by raw brute force, and in such cases no hooks would be able to run. However if you can trap the OS signal (for example SIGKILL) then you can fire the "Exit" command action and (we hope) shut down properly.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
You should checkout:
* The default close operation for JFrame and JDialog.
With both you can define what happens if you click on the (red) close icon of the window (JFrame, JDialog). The default close operation is HIDE_ON_CLOSE, which means that the JFrame/JDialog will no longer be visible, but it still holds resources. I prefer DISPOSE_ON_CLOSE (not EXIT_ON_CLOSE), as it allows the Event Dispatcher Thread to shutdown correctly once all windows are disposed. EXIT_ON_CLOSE calls System.exit, which terminates all threads immediately.