线程组实现:
package d1205;
public class GroupTest {
public static void main(String[] args) {
ThreadGroupTest groupTest = new ThreadGroupTest();
ThreadGroup threadGroup = new ThreadGroup("线程组");
//线程放入线程组
Thread thread = new Thread(threadGroup,groupTest,"线程");
threadGroup.setDaemon(true);
threadGroup.setMaxPriority(3);
System.out.println(thread.getName());
System.out.println(thread.getThreadGroup().getName());
System.out.println(thread.getThreadGroup().getParent().getParent());
}
}
线程组的作用:
- 从代码中可看出,方便线程统一管理
- 线程组可批量管理线程和线程组,呈树形结构
- 网图: