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

Log message is not logged in Shutdownhook

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.19042.1237]
      java version "17.0.1" 2021-10-19 LTS
      Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
      Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      When a message is logged in the Shutdownhook it is sometimes logged sometimes not.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case.
      I let it run 20 times. 11 times the message was not logged and 9 times the massage was logged.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Nov. 25, 2021 10:35:24 AM ShutdownHookLoggerBug main
      INFO: before add shutdown hook
      Nov. 25, 2021 10:35:24 AM ShutdownHookLoggerBug main
      INFO: after add shutdown hook
      Nov. 25, 2021 10:35:24 AM ShutdownHookLoggerBug lambda$main$0
      INFO: shutdown hook called

      ACTUAL -
      Nov. 25, 2021 10:35:24 AM ShutdownHookLoggerBug main
      INFO: before add shutdown hook
      Nov. 25, 2021 10:35:24 AM ShutdownHookLoggerBug main
      INFO: after add shutdown hook


      ---------- BEGIN SOURCE ----------
      import java.util.logging.Logger;

      public class ShutdownHookLoggerBug {
          public static void main(String[] args) {
              Logger.getLogger("mainLogger").info("before add shutdown hook");
              Runtime.getRuntime().addShutdownHook(new Thread(() -> Logger.getLogger("hookLogger").info("shutdown hook called")));
              Logger.getLogger("mainLogger").info("after add shutdown hook");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No workaround found.

      FREQUENCY : occasionally


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: