JDK-6261550 : (spec) Runtime.addShutdownHook should warn against depending upon other threads
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.3.1,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,windows_nt,windows_2000,windows_xp generic,windows_nt,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2005-04-26
  • Updated: 2011-01-31
  • Resolved: 2006-04-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b81Fixed
Related Reports
Duplicate :  
Relates :  
Description
If the user registers a shutdown hook using Runtime.addShutdownhook method and in the shutdown hook thread, trying to call Windows.dispose method to dispose the windows opened. This will cause deadlock. The reason of the deadlock is that shutdown hook is called from the Awt event dispatch thread and if in the user's shutwon hook thread, calling Windows.dispose or any action which requires Event Dispatch thread to be alive will cause deadlock. Below is a typical stack trace when the shutdown is called from AWT Event dispatch thread.

at java.lang.Object.wait(Native Method)
       - waiting on <0x03047e58> (a sun.awt.im.InputContext$1)
        at java.lang.Thread.join(Thread.java:1095)
        - locked <0x03047e58> (a sun.awt.im.InputContext$1)
        at java.lang.Thread.join(Thread.java:1148)
        at java.lang.Shutdown.runHooks(Shutdown.java:132)
        at java.lang.Shutdown.sequence(Shutdown.java:173)
        at java.lang.Shutdown.exit(Shutdown.java:218)
        - locked <0x06cad4b0> (a java.lang.Class)
        at java.lang.Runtime.exit(Runtime.java:90)
        at java.lang.System.exit(System.java:868)
        at Notepad$AppCloser.windowClosing(Notepad.java:195)
        at java.awt.Window.processWindowEvent(Window.java:1196)
        at javax.swing.JFrame.processWindowEvent(JFrame.java:266)
        at java.awt.Window.processEvent(Window.java:1154)
        at java.awt.Component.dispatchEventImpl(Component.java:4036)
        at java.awt.Container.dispatchEventImpl(Container.java:2023)
        at java.awt.Window.dispatchEventImpl(Window.java:1808)
        at java.awt.Component.dispatchEvent(Component.java:3873)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:591)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:247)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:168)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:162)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:154)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:115)

We probably should either document this behavior in the java doc of the Runtime.addShutdownhook or fire up the shutdown call in a different thread other than the Event dispatch thread.

###@###.### 2005-04-26 17:02:16 GMT

Comments
EVALUATION As suggested by the submitter, an advisory statement to the effect of Shutdown hooks also should not rely upon other threads, such as the AWT event-dispatch thread, which may already be dead or become blocked. will be added to the specification of the Runtime.addShutdownhook method. ###@###.### 2005-05-04 15:14:17 GMT
03-05-2005