Java.lang ThreadGroup
1 Java.lang ThreadGroup介绍
java.lang.ThreadGroup 类表示一组线程。它也可以包括其它的线程组。线程组构成一棵树,除了初始线程组中的每个线程组都有一个父类。
2 Java.lang ThreadGroup声明
public class ThreadGroup
extends Object
implements Thread.UncaughtExceptionHandler
3 Java.lang ThreadGroup方法
4 Java.lang ThreadGroup案例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
public class ThreadGroupDemo implements Runnable{
public void run() {
System.out.println(Thread.currentThread().getName());
}
public static void main(String[] args) {
ThreadGroupDemo runnable = new ThreadGroupDemo();
ThreadGroup tg1 = new ThreadGroup("Parent ThreadGroup");
Thread t1 = new Thread(tg1, runnable,"one");
t1.start();
Thread t2 = new Thread(tg1, runnable,"two");
t2.start();
Thread t3 = new Thread(tg1, runnable,"three");
t3.start();
System.out.println("Thread Group Name: "+tg1.getName());
tg1.list();
}
}
输出结果为:
one
two
three
Thread Group Name: Parent ThreadGroup
java.lang.ThreadGroup[name=Parent ThreadGroup,maxpri=10]
Thread[one,5,Parent ThreadGroup]
Thread[two,5,Parent ThreadGroup]
Thread[three,5,Parent ThreadGroup]
热门文章
优秀文章