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

The java logging package needs to allow explicit control of when it shuts down

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Future Project
    • Icon: P4 P4
    • None
    • 5.0, 7
    • core-libs

      A DESCRIPTION OF THE REQUEST :
      The java log manager registers a shutdown hook that runs paralell to the applications shutdown hooks. This causes any shutdown logging to be haphazard at best.

      JUSTIFICATION :
      For applications with a complicated shutdown profile, it is absolutely critical to be able to generate log events during shutdown in order to debug any problems with the shutdown process.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Explicit application control over when the java log manager gets shutdown so that the application can reliably generate log events during shutdown processing.
      ACTUAL -
      During shutdown, log events are ignored.

      ---------- BEGIN SOURCE ----------
      package com.snapin.xbl;

      import java.util.logging.*;

      import com.snapin.util.Util;

      /**
       * @author davep
       *
       */
      public class Test
      {
      protected static Logger log = Logger.getLogger(ConsoleServer.class.getName());

      protected static Object event = new Object ();

      /**
      * @author dave
      *
      */
      public static class ShutdownHook implements Runnable
      {
      public void run ()
      {
      try
      {
      log.info("Running shutdown handler on application...");

      Thread.sleep(5000);

      synchronized (Test.event)
      {
      Test.event.notifyAll();
      }

      log.info("Finished shutdown handler");
      }
      catch (Throwable e)
      {
      log.warning ("Unable to shutdown application" + Util.eol + Util.getExceptionString (e));
      }
      }

      }

      /**
      * @param args
      */
      public
      static
      void
      main (
      String[] args
      )
      {
      Thread thread;

      thread = new Thread (new ShutdownHook ());

      Runtime.getRuntime().addShutdownHook(thread);

      {
      Handler handler = new ConsoleHandler ();

      handler.setLevel(Level.FINEST);
      handler.setFormatter(new SimpleFormatter ());
      Logger.getLogger("").addHandler(handler);
      Logger.getLogger("").setLevel(Level.FINEST);
      }

      log.fine ("Waiting for application to shutdown...");

      //
      // Wait forever
      //
      try
      {
      synchronized (Test.event)
      {
      Test.event.wait();
      }
      }
      catch (InterruptedException e)
      {
      System.out.println (e.getMessage());
      }

      log.info("Application was shutdown");
      }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use appache's log4j

            Unassigned Unassigned
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: