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
You can configure a security policy for your program or add SecurityManager.
SecurityManager
, System.exit ( ), SecurityManager checkExit. Runtime#removeShutdownHook.
System.exit
checkExit
Runtime#removeShutdownHook
, JDK 1.8. , .
, , JNI ( ).