public class Example7 {
public static void main(String[] args) {
Thread newThread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {}
}
});
newThread.start();
Thread newThread2 = new Thread(newThread.getThreadGroup(), new Runnable() {
@Override
public void run() {
while (true) {}
}
},"newThread2");
newThread2.start();
System.out.println(newThread.getThreadGroup().getMaxPriority());
System.out.println(newThread.getThreadGroup().getParent());
System.out.println(newThread.getThreadGroup().activeCount());
ThreadGroup tGroup = newThread.getThreadGroup();
//列出线程组
tGroup.list();
ThreadGroup pGroup = tGroup.getParent();
if(pGroup!=null)pGroup.list();
ThreadGroup gpGroup = pGroup!=null ? pGroup.getParent():null;
if(gpGroup!=null)gpGroup.list();
}
}