我正在阅读书Java -完整的参考中关于Fork/Join框架的内容。它说ForkJoinPool使用守护进程线程:
ForkJoinPool使用守护进程线程。当所有用户线程都已终止时,守护进程线程将自动终止。因此,不需要显式关闭ForkJoinPool。但是,除了公共池之外,还可以通过调用so ( )来做到这一点。关闭()方法对公共池没有任何影响。
ForkJoinWorkerThread都是守护进程线程?ForkJoinPool用于重要的任务?shutdown()是否等待工作线程完成?发布于 2020-07-22 08:53:04
1.
jshell> ForkJoinPool.commonPool().execute(() -> System.out.println(Thread.currentThread().getClass() + " isDaemon? " + Thread.currentThread().isDaemon()))
class java.util.concurrent.ForkJoinWorkerThread isDaemon? true
jshell>A:是的,它们是守护进程线程。
2.
jshell> new Thread(() -> System.out.println("isDaemon? " + Thread.currentThread().isDaemon() + " priority:" + Thread.currentThread().getPriority())).start()
isDaemon? false priority:5
jshell> ForkJoinPool.commonPool().execute(() -> System.out.println("isDaemon? " + Thread.currentThread().isDaemon() + " priority:" + Thread.currentThread().getPriority()))
isDaemon? true priority:5A:默认情况下,ForkJoinPool创建与任何其他线程具有相同优先级的线程。
3.
来自ForkJoinPool#commonPool的javadoc
返回公共池实例。这个池是静态构造的;它的运行状态不受关闭()或shutdownNow()尝试的影响。然而,这个池和任何正在进行的处理都会在程序System.exit(int)上自动终止。任何在程序终止前依赖异步任务处理来完成的程序都应该在退出之前调用commonPool().awaitQuiescence。
awaitQuiescence A:ForkJoinPool忽略关机,但应用程序可以调用以确保所有任务都完成。
发布于 2020-07-22 08:52:15
https://stackoverflow.com/questions/63029461
复制相似问题