I was wonder if anybody knows how to take shut down a java program when the restart or the shutdown command is given in windows. What i mean is i want to be able to hook into this command and have my application shutdown automatically before windows shuts down.
Are you sure it isn't already? From the JavaDocs for java.lang.RunTime.addShutdownHook (jdk 1.4) The Java virtual machine shuts down in response to two kinds of events: * The program exits normally, when the last non-daemon thread exits or when the exit (equivalently, System.exit) method is invoked, or * The virtual machine is terminated in response to a user interrupt, such as typing ^C, or a system-wide event, such as user logoff or system shutdown.
But what if someone presses CTRL+C and shutdown the VM, or sends a kill signal in Unix/Linux? Will your memory-buffered logfile not be written to disk, with the loss of important information as a consequence? The only way to make some code execute right before the VM shuts down is using shutdown hooks. And that's exactly what this article will teach you.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Oct 24, 2002
I know about this type of hooking but what i am looking for is when Windows goes to shutdown or restart.....is there a way for us to see that Windows is doing this and can we do stuff based on these events?
subject: Hooking into the windows restart or shutdown commands