Note how most of the other calls Logger
calls work, and all the System.out.println()
works, but please someone explain to me why the Logger.info()
calls in stop()
and in destroy()
never print with the rest of the log, since those functions are clearly running!? With java12, even the destroy()
isn't showing. Is this a bug, am I using it weird, or what?
package test;
import java.util.logging.Logger;
public class Test {
private static Logger LOGGER = Logger.getLogger(Test.class.getCanonicalName());
public static void main(String[] args) {
System.out.println("main()");
LOGGER.info("main()");
new Test();
}
private Test() {
LOGGER.info("Test()");
System.out.println("Test()");
Runtime.getRuntime().addShutdownHook(new ShutdownThread());
}
public void shutdown() throws Exception {
LOGGER.info("shutdown()");
System.out.println("shutdown()");
stop();
destroy();
}
public void stop() throws Exception {
LOGGER.info("stop()");
System.out.println("stop()");
}
public void destroy() {
LOGGER.info("destroy()");
System.out.println("destroy()");
}
class ShutdownThread extends Thread {
ShutdownThread() {
super("app-shutdown-hook");
}
@Override
public void run() {
try {
shutdown();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Bye! ♂️");
}
}
}
OUTPUT with both java 10 and java 11 (OpenJDK):
main()
Mar 14, 2020 1:53:59 PM test.Test main
INFO: main()
Mar 14, 2020 1:53:59 PM test.Test <init>
INFO: Test()
Test()
Mar 14, 2020 1:53:59 PM test.Test shutdown
INFO: shutdown()
shutdown()
stop()
destroy()
Bye! ♂️
OUTPUT with java 12 (OpenJDK):
main()
Mar 14, 2020 2:17:13 PM test.Test main
INFO: main()
Mar 14, 2020 2:17:13 PM test.Test <init>
INFO: Test()
Test()
shutdown()
stop()
destroy()
Bye! ♂️