console java application. Someone kill java.exe process by Task Manager. How can I write to logs some information at this moment before application is terminated?
Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) { ..... }
});
OR
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() { ..... }
});
don’t execute in such situation
This is not possible. Shutdown hooks will only be executed in an orderly shutdown:
You can send another signal that will trigger an orderly shutdown like
SIGINT. Killing a application should be the last resort after the application did not respond.