As explained in http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html, JVM on Windows starts shutdown upon CTRL_LOGOFF_EVENT, unless the -Xrs option is set. As this document also explains, this behavior is undesirable for a Windows service. The problem here is that if a Windows service can launch JVMs possible indirectly (such as a Windows service launching cmd.exe to do a batch file, which in turn launches JVM), and therefore adding -Xrs to every JVM invocation is neither practical nor desirable --- those JVMs that are indirectly launched may have no clue that it's running as a service, hence we can't expect their launcher scripts to have -Xrs. According to the current MSDN documentation <http://msdn.microsoft.com/en-us/library/ms683242(VS.85).aspx>, CTRL_LOGOFF_EVENT is explained as follows: A signal that the system sends to all console processes when a user is logging off. This signal does not indicate which user is logging off, so no assumptions can be made. Note that this signal is received only by services. Interactive applications are terminated at logoff, so they are not present when the system sends this signal. So I find it odd that JVM initiates a shutdown hook in this case --- only a Windows service gets this, but they shouldn't initiates a shutdown! We'd be all better off if JVM ignores CTRL_LOGOFF_EVENT whatsoever. If such change is impossible due to the compatibility constraints, I request that JVM recognizes an environment variable to activate -Xrs. Environment variables are inherited through a process tree, so in the situation described above, I can set it once at the service process and every JVM spawned directly/indirectly will have a proper protection against CTRL_LOGOFF_EVENT.
|