RFR(s): Support graceful application termination on Windows shutdown/logoff

Nikola Grcevski Nikola.Grcevski at microsoft.com
Fri Jul 24 01:47:41 UTC 2020

Hello hotspot-runtime-dev,

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:


It appears that this issue was logged in JSB at some point, but it was
made duplicate of another issue:


The behaviour changed going from Windows Vista to Windows 7.

I've made a proposal patch to address this issue under the following webrev:


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. If this patch is accepted I can submit a
follow-up patch for AWT to resolve the possible issues.

Finally, there are third set of events for service processes, for example  
java applications which are started with a Windows Service wrappers. These
Once the most common case is resolved, I'd like to submit perhaps a follow-up patch
to support graceful termination of Java as Windows service programs.

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.

Thanks in advance for reviewing this.

Nikola Grcevski

More information about the hotspot-runtime-dev mailing list