Java ThreadGroup setDaemon() 方法

2024 年 11 月 11 日 | 阅读 1 分钟

ThreadGroup 类的 setDaemon() 方法用于测试线程组是否为守护线程组。

语法

参数

daemon:如果为 true,则将线程组标记为守护线程组;否则,将其标记为普通线程组。

Exception

SecurityException:如果当前线程无法修改该线程组。

示例

输出

Is Parent thread a daemon threadGroup? true
Is Child thread a daemon threadGroup? false
Thread-1 completed executing
Thread-2 completed executing