【发布时间】:2011-08-10 12:10:03
【问题描述】:
是否可以编写一个 System.exit 在终止程序时调用的方法?
【问题讨论】:
标签: java exit-code system.exit
是否可以编写一个 System.exit 在终止程序时调用的方法?
【问题讨论】:
标签: java exit-code system.exit
关闭挂钩就是答案...here is an article on them。它们并非没有问题(其中一些在文章中进行了讨论)。
【讨论】:
您可以使用关闭挂钩。
http://download.oracle.com/javase/6/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
请注意,如果 VM 异常中止或调用 Runtime.halt(int),则关闭挂钩将不会运行。
【讨论】:
您可以添加VM shutdown hook。
【讨论】: