How does a JVM running multiple threads handle ctrl-c, w/ and w/o shutdown hooks?

被刻印的时光 ゝ 提交于 2019-12-06 03:13:23

The classic book "Java Concurrency in Practice" has a chapter (7.4) on the JVM shutdown, you should read that, but here are some relevant quotes:

If any application threads (daemon or nondaemon) are still running at shutdown time, they continue to run concurrently with the shutdown process.

The JVM makes no attempt to stop or interrupt any application threads that are still running at shutdown time; they are abruptly terminated when the JVM eventually halts.

So the threads are not interrupted, but you can interrupt them explicitly from the shutdown hook, if you wish.

devOpsTools

IMO, Daemon threads will continue to run during shutdown process and JVM will kill all running threads later when its time to exit the application. I don't think, running threads will get InterruptedException as JVM doesn't make any extra effort to stop running threads.

http://www.tutorialspoint.com/java/lang/runtime_addshutdownhook.htm

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