NOTE: Opening this bug on behalf of Nikola Grcevski
After some recent investigation into stale files remaining after Java process terminates on Windows shutdown, we noticed that there's missing support for detecting Windows shutdown/logoff events for interactive Java applications. Given that Java loads both GDI32.dll and USER32.dll, even for console applications, this means that almost all Java processes launched on Windows don't run any shutdown hooks at the moment on user logoff or system shutdown/restart.
Since Windows 7, all Windows applications that load (or transitively call) GDI32.dll or USER32.dll will not receive the CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT events, but instead they will be sent WM_ENDSESSION.
This is documented in MSDN under the following article:
https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler
It appears that this issue was logged in JSB at some point, but it was made duplicate of another issue:
https://bugs.openjdk.java.net/browse/JDK-8079631
The behaviour changed going from Windows Vista to Windows 7.
I've made a proposal patch to address this issue under the following webrev:
http://cr.openjdk.java.net/~adityam/nikola/wm_endsession_handling/
At the moment only AWT applications would terminate gracefully on shutdown/logoff, because they have support for listening on WM_ENDSESSION.
There's a bug in the AWT code, it doesn't check for wparam upon receiving the event, but it will work in most cases. A follow-up bug may need to be opened for AWT to resolve the possible issue of the user changing their mind on shutdown.
We are working to amend the MSDN documentation for SetConsoleCtrlHandler to specify that this behaviour change is also present on server OSs. The documentation only mentions the workstation OS flavours at the moment.
This bug affects all Java versions running on Windows 7 and later.
After some recent investigation into stale files remaining after Java process terminates on Windows shutdown, we noticed that there's missing support for detecting Windows shutdown/logoff events for interactive Java applications. Given that Java loads both GDI32.dll and USER32.dll, even for console applications, this means that almost all Java processes launched on Windows don't run any shutdown hooks at the moment on user logoff or system shutdown/restart.
Since Windows 7, all Windows applications that load (or transitively call) GDI32.dll or USER32.dll will not receive the CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT events, but instead they will be sent WM_ENDSESSION.
This is documented in MSDN under the following article:
https://docs.microsoft.com/en-us/windows/console/setconsolectrlhandler
It appears that this issue was logged in JSB at some point, but it was made duplicate of another issue:
https://bugs.openjdk.java.net/browse/JDK-8079631
The behaviour changed going from Windows Vista to Windows 7.
I've made a proposal patch to address this issue under the following webrev:
http://cr.openjdk.java.net/~adityam/nikola/wm_endsession_handling/
At the moment only AWT applications would terminate gracefully on shutdown/logoff, because they have support for listening on WM_ENDSESSION.
There's a bug in the AWT code, it doesn't check for wparam upon receiving the event, but it will work in most cases. A follow-up bug may need to be opened for AWT to resolve the possible issue of the user changing their mind on shutdown.
We are working to amend the MSDN documentation for SetConsoleCtrlHandler to specify that this behaviour change is also present on server OSs. The documentation only mentions the workstation OS flavours at the moment.
This bug affects all Java versions running on Windows 7 and later.
- relates to
-
JDK-7068835 shutdown hooks are not executed when closing console
-
- Closed
-