下面的代码中,先获取了当前线程所在的线程组,然后获得了父线程组:
package com.thb;
public class Test5 {
public static void main(String[] args) {
ThreadGroup currentThreadGroup = Thread.currentThread().getThreadGroup();
ThreadGroup parentThreadGroup = currentThreadGroup.getParent();
System.out.println("current thread group: "+ currentThreadGroup);
System.out.println("parent thread group: "+ parentThreadGroup);
}
}
运行输出: