-
Enhancement
-
Resolution: Future Project
-
P4
-
None
-
5.0, 7
-
x86
-
windows_xp, windows_vista
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
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
- relates to
-
JDK-8161253 LogManager$Cleaner() can prevent logging in other shutdown hooks
- Open