线程组ThreadGroup
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了线程组ThreadGroup相关的知识,希望对你有一定的参考价值。
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(); } }
以上是关于线程组ThreadGroup的主要内容,如果未能解决你的问题,请参考以下文章