Java ThreadGroup parentOf() 方法

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

ThreadGroup 类的 **parentOf()** 方法用于测试该线程组是否为参数线程组本身,或其祖先线程组之一。

语法

参数

g: 线程组

返回

如果调用线程是组的父线程,则返回 true。否则,返回 false。

示例

输出

Thread-1 starts
Thread-2 starts
Child thread is the parent of Parent thread: false
Parent thread is the parent of Child thread: true
Thread-1 completed executing
Thread-2 completed executing