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

Calling System.exit from a Shutdown hook causes hang

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 6u12
    • core-libs

      FULL PRODUCT VERSION :
      (CentOS)
      java version "1.6.0_12"
      xJava(TM) SE Runtime Environment (build 1.6.0_12-b04)
      Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

      (Ubuntu)
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.60.0_03-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.6.18-92.1.22.el5 (CentOS 5.2)
      Linux 2.6.22-16-generic (Ubuntu 7.10)


      A DESCRIPTION OF THE PROBLEM :
      When a shutdown hook contains System.exit() the jvm will hang and not close properly.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the attached source code and run as:
      java Hook.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting the JVM to exit.
      ACTUAL -
      The JVM hangs.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Hook {
      public static void main(String[] args) {
      Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      public void run() {
      System.exit(0);
      }
      }));
      System.out.println("Hook registered");
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't call system.exit from inside a shutdown hook.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: