...
- Hook threads should be light-weight and simple
- They should be thread safe
- They should hold locks while accessing data
Wiki Markup They should not rely on system services as they themselves may be shutting down (for example, the logger may shutdown from another hook). Instead of one service it may be better to run a series of shutdown tasks from one thread by using a single shutdown hook. \[[Goetz 06|AA. Java References#Goetz 06]\]
This compliant solution shows the method to install a hook.
...
Wiki Markup |
---|
\[[API 06|AA. Java References#API 06]\] [method checkExit()|http://java.sun.com/j2se/1.4.2/docs/api/java/lang/SecurityManager.html#checkExit(int)], Class Runtime, method addShutdownHook
\[[Kalinovsky 04|AA. Java References#Kalinovsky 04]\] Chapter 16 Intercepting a Call to System.exit
\[[Austin 00|AA. Java References#Austin 00]\] [Writing a Security Manager|http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed2.html]
\[[Darwin 04|AA. Java References#Darwin 04]\] 9.5 The Finalize Method
\[[Goetz 06|AA. Java References#Goetz 06]\] 7.4. JVM Shutdown
\[[ESA 05|AA. Java References#ESA 05]\] Rule 78: Restrict the use of the System.exit method
\[[MITRE 09|AA. Java References#MITRE 09]\] [CWE ID 382|http://cwe.mitre.org/data/definitions/382.html] "J2EE Bad Practices: Use of System.exit()" |
...