Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6261550
Votes 0
Synopsis (spec) Runtime.addShutdownHook should warn against depending upon other threads
Category java:classes_lang
Reported Against 1.3.1
Release Fixed mustang(b81)
State 10-Fix Delivered, request for enhancement
Priority: 4-Low
Related Bugs 6301682 , 4712342
Submit Date 26-APR-2005
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. customer .InputContext$1)
        at java.lang.Thread.join(Thread.java:1095)
        - locked <0x03047e58> (a sun.awt. customer .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.

  xxxxx@xxxxx   2005-04-26 17: customer :16 GMT
Work Around
N/A
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.

  xxxxx@xxxxx   2005-05-04 15:14:17 GMT
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang