Thread group to achieve:
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());
}
}
The role of thread groups:
- As can be seen from the code, to facilitate unified management thread
- Thread group can manage batch threads and thread groups, showing a tree structure
- Network map: