Running code on program exit in Java

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 22:38:49

Shutdown hooks are the answer... here is an article on them. They do not come without issues (some of them are discussed in the article).

You can use a shutdown hook.

http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)

Note that shutdown hooks will not run if the VM aborts abnormally or Runtime.halt(int) is called.

lobster1234

You can add a VM shutdown hook.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!