1.线程组ThreadGroup
线程是可以被组织的,java中存在线程组的概念,每个线程都可以有自己的线程组。线程组把多个线程组合为一个对象,通过对线程组可以同时操作多个线程。比如:获取线程组中线程个数,启动线程等。
2.应用
package se.thread; public class ThreadGroupTest { public static void main(String[] args) { ThreadGroup group1 = new ThreadGroup("group1"); ThreadGroup group2 = new ThreadGroup(group1,"group2"); Thread t1 = new Thread(group1,new ThreadTest(3000,"jack")); Thread t2 = new Thread(group2,new ThreadTest(3000,"kal")); Thread t3 = new Thread(group2,new ThreadTest(3000,"gg")); t1.start(); t2.start(); t3.start(); group2.stop(); } }