threadgoup

分门别类的管理,线程组

DEMO

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

package concurrent;


* @description 类描述:
* @author 作者:LIYONG
* @create 创建时间:2017-4-14
* @update 修改时间:2017-4-14
*/

public class implements Runnable {

public void run() {
String groupName = Thread.currentThread().getThreadGroup().getName()+"&&"+Thread.currentThread().getName();
while(true){
System.out.println(groupName);
try {
Thread.sleep(4*1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
public static void main(String[] args) {
ThreadGroup group = new ThreadGroup("group");
ThreadGoupTest test = new ThreadGoupTest();

Thread t1 = new Thread(group, test, "aaaaaa");
t1.setPriority(10);
t1.start();
Thread t2 = new Thread(group, test, "bbbbbb");
t2.setPriority(1);
t2.start();
}

}