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

Shutdown hook for application image does not work on Windows

XMLWordPrintable

    • b01
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      jdk-21.0.2+13 later

      A DESCRIPTION OF THE PROBLEM :
      The changes made in JDK-8301247 have caused the shutdown hook to stop working.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create App.java as follows.

      ```
      public class App {

          public static void main(String[] args) {

              System.out.println("java.vm.version: " + System.getProperty("java.vm.version"));

              Runtime.getRuntime().addShutdownHook(new Thread("My Shutdown Hook") {
                  public void run() {
                      System.out.println("ShutdownHook started");
                      try { Thread.sleep(3000); } catch (Exception e) { }
                      System.out.println("ShutdownHook finished");
                  }
              });

              while (true) {
                  try {
                      Thread.sleep(3000);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  System.out.print(".");
              }
          }
      }
      ```

      ```
      javac .\App.java
      jar -cvfe libs\app.jar App *.class
      jpackage --type app-image --win-console --name app --input libs --main-jar app.jar
      .\app\app.exe
      ```

      Run the application and press Ctrl-C.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      We expect the shutdown hook to complete processing.
      In jdk-21.0.1+12, the shutdown hook runs and “ShutdownHook finished” is displayed.
      ACTUAL -
      In jdk-21.0.2+13, jdk-21.0.8+9, and other versions, “ShutdownHook finished” is not displayed and the shutdown hook processing is not completed.

            asemenyuk Alexey Semenyuk
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: