将“守护程序”状态传播到Java中的所有子线程 [英] Propagating "daemon"-status to all child-threads in Java

查看:101
本文介绍了将“守护程序”状态传播到Java中的所有子线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I have a Thread object, I can call setDaemon(true) on it to mark that this thread should not prevent application shutdown if all other non-daemon threads have terminated.

是否有可能使此行为自动滴流到所有人子线程?即如果我有一个标记为守护程序线程的线程,是否有某种方法可以强制该线程产生的所有线程也自动标记为守护程序线程?

Is it possible to make this behavior automatically trickle down to all child-threads? I.e. if I have a thread that is marked as a daemon-thread, is there some way to enforce that all threads spawned by this thread are also automatically marked as daemon-threads?

推荐答案


是否可以使这种行为自动滴流到所有
子线程?

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

您不需要这样做,因为默认情况下:

You don't need to do that since it is by default:


新创建的当且仅当创建它的线程当前被标记为守护程序
线程时,该线程才最初被标记为守护程序线程
。 setDaemon方法可用于更改
线程是否是守护程序。

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.

请参见

这篇关于将“守护程序”状态传播到Java中的所有子线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆