tags:

views:

160

answers:

3

Hi, I am having lot of CPU and IO intensive code in shutdown hook. Some times I see they are not getting executed properly. So Is there any limitation like we should not have lot of code in shutdown hook.

Thanks D. L. Kumar

+1  A: 

Shutdown hooks are not guaranteed to run. Process abortion by killing the process or hardware failures are typical cases when shutdown hooks are not run.

David Schmitt
Thanks for ur reply. I am dumping two files. Some times they get dumped properly, Some times not. Here there are no hardware failures or killing processes. It is just happening randomly.
+2  A: 

I have placed some fairly substantial code in a shutdown hook for one of my apps, and it executes very reliably on a variety of O/S's (Windows XP, Vista, AS400/iSeries/Systemi, Linux) under a variety of circumstances, including sigterms and Windows shutdown.

But beware of any system's shutdown timeout (ala Windows good ol' this program is not responding dialog).

Also beware true O/S kill commands, like Linux sigkill (?) and Windows task manager's end process.

Software Monkey
+2  A: 

Simply No. Read carefully API and you will see. There is limited time to shutdown. If you extend over this time slot the JVM will simply end/terminate without notification. If you are writing data, you will write down corrupted data.

Rastislav Komara
Thanks a lot for info. I should have read it.