java - 将 "daemon"-status 传播到 Java 中的所有子线程

标签 java multithreading daemon

如果我有一个 Thread 对象,我可以在它上面调用 setDaemon(true) 来标记这个线程不应该阻止应用程序关闭,如果所有其他非守护线程已经终止。

是否可以让这种行为自动渗透到所有子线程? IE。如果我有一个标记为守护线程的线程,是否有某种方法可以强制此线程生成的所有线程也自动标记为守护线程?

最佳答案

Is it possible to make this behavior automatically trickle down to all child-threads?

您不需要这样做,因为它是默认设置:

The newly created thread is initially marked as being a daemon thread if and only if the thread creating it is currently marked as a daemon thread. The method setDaemon may be used to change whether or not a thread is a daemon.

参见 this .

关于java - 将 "daemon"-status 传播到 Java 中的所有子线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17760951/

相关文章:

java - div 的 Angular ng 变化

java - Intent JSONObject 到另一个 Activity

java - 在java中缓存方法的结果

android - Bolts Tasks 可以在 Android 上并行运行 bolts 返回非 Void 类型吗?

python - python3多线程写入文件

java - 如何在 List(不是 List)的 Function<T, R> 参数中应用

c# - 进度条显示方法的执行

C++ 无限轮流运行两个函数(线程)

linux - 为以用户身份运行的守护进程存储 pid 文件

java - 如何处理从xml到Activity的点击