Staff completion of the program - catches Listener Emergency - Runtime.getRuntime (). AddShutdownHook (shutdownHook)
And how to catch the situation when the program was stopped from the development environment, for example IntelijIdea?
Staff completion of the program - catches Listener Emergency - Runtime.getRuntime (). AddShutdownHook (shutdownHook)
And how to catch the situation when the program was stopped from the development environment, for example IntelijIdea?
If you run the application in Intellij Idea
and try to leave it by clicking on the red box.
Idea
generates an interrupt signal from the operating system and sends it to the java process. This signal can be processed within the program. This is done as follows (valid for linux, for other OS the name of the signal may differ):
Signal.handle(new Signal("INT"), new SignalHandler() { public void handle(Signal sig) { System.out.println("ой, меня кто то хочет остановить"); System.exit(0); } });
This code adds a handler for the Interrupt from keyboard
system event, displays a message in the console, and stops the application.
Source: https://ru.stackoverflow.com/questions/558000/
All Articles