编程语言
首页 > 编程语言> > java – 运行多个线程的JVM如何处理ctrl-c,w /和w / o shutdown hooks?

java – 运行多个线程的JVM如何处理ctrl-c,w /和w / o shutdown hooks?

作者:互联网

在网上找不到这个答案.当按下Ctrl C时:

>当我们没有任何关闭钩子时,正在运行的线程会发生什么 – 他们每个都被InterruptedException击中?
>当我们有关闭钩子时,我知道关闭钩子以任意顺序在新线程中运行.但是现有的运行线程会发生什么?他们是否仍然受到InterruptedException的攻击?

谢谢!

解决方法:

经典着作“Java Concurrency in Practice”有关于JVM关闭的章节(7.4),您应该阅读它,但这里有一些相关的引用:

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.

因此,线程不会被中断,但如果您愿意,可以从关闭钩子中明确地中断它们.

标签:terminate,shutdown-hook,java,multithreading
来源: https://codeday.me/bug/20190824/1711452.html