When Shutdown Hooks Break Bad

前端 未结 5 613
暖寄归人
暖寄归人 2021-01-17 16:53

If I add a shutdown hook to my Java program\'s runtime like so:

public class MyShutdownHook implements Runnable
{
    @Override
    public void run(         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-17 17:26

    Any time the JVM can exit gracefully, the shutdown hook is run. It is not run if:

    • The JVM crashes. (Depending on how/when it crashes, the hook may still run, but no guarantees are made)
    • The JVM gets SIGKILL or similar, and is immediately stopped by the OS

提交回复
热议问题