2.4线程组创建

public class 线程组创建 {
public static void main(String[] args) {
ThreadGroup threadGroup=new ThreadGroup("my");
threadGroup.setMaxPriority(5);
System.out.println(threadGroup.getMaxPriority());
//getMaxPriority() 可以通过这个函数 知道这个线程组的最大长度
Thread t1=new Thread(threadGroup, new Runnable() {
public void run() {
System.out.println("线程组 子线程1");
}
},"T1");
Thread t2=new Thread(threadGroup, new Runnable() {
public void run() {
System.out.println("线程组 子线程2");
}
},"T2");
t1.start();
t2.start();
System.out.println(threadGroup.activeCount());
System.out.println(threadGroup.activeGroupCount());
System.out.println("-----------");
threadGroup.list();
}
}
posted @ 2018-02-07 10:29  anxbb  阅读(261)  评论(0编辑  收藏  举报