天天看点

监听JVM关闭

使用runtime的addshutdownhook(thread)方法:

输出结果:

监听JVM关闭

也可使用runtime.removeshutdownhook(thread)移除监听线程。