package com.ccy.thread.demo;
import org.junit.Test;
public class ThreadGroupDemo {
@Test
public void test(){
ThreadGroup group = new ThreadGroup("test");
new Thread(group,new MyThead()).start();
new Thread(group,new MyThead()).start();
new Thread(group,new MyThead()).start();
//打印出该线程组的信息
group.list();
//该线程组的活动线程 结果为 :3
System.out.println(group.activeCount());
//父线程组 结果为:main(主线程)
System.out.println(group.getParent().getName());
}
}
class MyThead implements Runnable{
@Override
public void run() {
for(int i =0;i<Integer.MAX_VALUE;i++){
System.out.println(Thread.currentThread().getName()+"输出:"+i);
}
}
}
更多多线程精彩内容请继续关注我的博客:http://blog.csdn.net/caicongyang
记录与分享,你我共成长 -from
caicongyang