java.util.logging and addShutdownHook at shutdown

D

Dave

Hello,

I'm having trouble logging messages while the JVM is shutting down.
It seems that the logging infrastructure silently breaks as soon as
shutdown starts. In the program below, after sending a ctrl-c, I
still get "."s, but no logging messages, and no error messages either.
It seems to me that this limits logging in a crucial way, and I'd
like to find out that there is a way around it. Can anyone shed light
on this?

Java 1.4.1_03-b02 running on WinXP


import java.util.logging.*;

public class testing {

static Logger logger = Logger.getLogger("testing");

public static void main(String[] args) {

Thread shutdown_thread = new Thread(new Runnable() {
public void run() {
System.out.println("Shutting down");
try{
Thread.sleep(1000);
}
catch(InterruptedException e){
System.out.println("Sleep Interrupted");
}
System.out.println("down");
}});

Runtime.getRuntime().addShutdownHook(shutdown_thread);

try {
while (true) {
System.err.print(".");

logger.severe("+");
try{
Thread.sleep(100);
}
catch(InterruptedException e){
System.out.println("Sleep Interrupted");
}
}
} catch (Exception ee) {
System.out.println("done");
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top