When do I need to call this method Runtime.getRuntime().addShutdownHook()

后端 未结 3 1356
梦如初夏
梦如初夏 2020-12-02 13:21

When do I actually need call this method Runtime.getRuntime().addShutdownHook() and when or why I need to shutdown my application. Could anyone please explain me this by giv

3条回答
  •  情歌与酒
    2020-12-02 13:52

    One case is, If you any daemon threads which needs to be stopped before your jvm shutdown (or) any other backend threads (mostly daemon threads) need to be gracefully exited, you will write shutdown hook and execute it using above code. Here is interesting discussion we had on SO couple of days ago. Shutdown hook

提交回复
热议问题