Differentiate shutdowns more than Runtime.setShutdownHook () in Java

Is there a way to add a shutdown hook that only starts when the program shuts down due to system shutdown.

I do not want the code to work when the code ends regularly, only on other outputs.
With addShutDownHook Thread works no matter how the program terminates

+4
source share
2 answers

You can configure a security policy for your program or add SecurityManager.

, System.exit ( ), SecurityManager checkExit. Runtime#removeShutdownHook.

+3

, JDK 1.8. , .

, ​​ , JNI ( ).

+1

All Articles