Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Shutdown hook does not work when system shuts down

843798Feb 29 2008 — edited Jul 3 2008
Hi all!

I am facing a probem using the shutdown hook technology to do some file operations when my application quits. As my application is a tray app it normally starts when the system comes up and is not quit by the user but by shuting down or logging off. For this I wanted to use a shutdown hook thread that is executed when the virtual machine quits. This works fine if System.exit() gets called out of my application, e.g. if the user quits the app by selecting the exit item in the tray menu. However, when the JVM is quit by a user logoff or system shutdown, the shutdown thread is not executed completely. Not all file operations are done because the system shuts down immediately without waiting for the shutdown thread. I figured this out by inserting a Thread.sleep() in the shutdown thread. If I close the app in menu it works, when shutting the system down no (not even a second) wait is performed. Is there a time limit for operations in the shutdown thread? If I take a look at javaw.exe in task manager I see it gets killed immediatly after shutdown is engaged.

I use Windows Vista. Are there probably differences in shutdown procedure compared to XP?

Thanks a lot! Greetings, Sebastian
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 31 2008
Added on Feb 29 2008
12 comments
2,114 views