Reputation: 9
I am working on a java application in which i have to perform a task if user shutdown the computer without closing my java application. I heard about "Java shutdown hook" as solution for my problem So I implemented the Java Shutdown hook I my main method
CheckInPageController controller = new CheckInPageController();
Runnable shutdownHandler = new Runnable() {
@Override
public void run() {
System.out.println("Shutting down thread..");
controller.performShutdownHook();
}
};
Runtime.getRuntime().addShutdownHook(
new Thread(shutdownHandler, "shutdownthread"));
launch(args);
Here controller.performShutdownHook() is method which simply sends a POST request to the server. But my problem is if I close the appplication by using close button, Shutdown hook is executing. But if I shutdown the computer without closing application shutdown hook is not executing which is my main requirement.
Plese tell me why this is happpening. If anyone have other solution of my problem please mention your solution. Thanks in advance.
Upvotes: 0
Views: 108