Women in Technology

Hear us Roar



Article:
  Surviving Abrupt Shutdown
Subject:   restrictions in shutdown hooks
Date:   2004-01-14 21:10:25
From:   anonymous2
Nice article. Just wanted to add one caveat: Last I checked (about a year ago), there were one or two serious limitations to what you could do in a shutdown hook, just because some of the standard libraries have their own hooks which may run before yours. The one that got me was that all of your logs from java.util.logging were already closed and hence unusable.


From the java.lang.Runtime.addShutdownHook javadoc:
Shutdown hooks run at a delicate time in the life cycle of a virtual machine and should therefore be coded defensively. They should, in particular, be written to be thread-safe and to avoid deadlocks insofar as possible. They should also not rely blindly upon services that may have registered their own shutdown hooks and therefore may themselves in the process of shutting down.


Just something to be aware of...