码迷,mamicode.com
首页 > 编程语言 > 详细

线程组ThreadGroup

时间:2016-02-01 17:58:48      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:

 

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

标签:

原文地址:http://www.cnblogs.com/barker/p/5175561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!