Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6261550

(spec) Runtime.addShutdownHook should warn against depending upon other threads

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b81
    • CPU:
      generic, x86
    • OS:
      generic, windows_nt, windows_2000, windows_xp

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mr Mark Reinhold
              Reporter:
              xlu Xiaobin Lu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: