
7

Java基础SE(三) 线程与并发-补充
source link: https://zhouj000.github.io/2021/05/24/java-base-thread2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Java基础SE(三) 线程与并发-补充
Java基础SE(一) 数据类型与关键字
Java基础SE(二) 集合
Java基础SE(三) 线程与并发
Java基础SE(三) 线程与并发-补充
Java基础SE(四) IO
Java基础: JVM(九) Java内存模型
Java性能优化02-并行优化
对相同性质的线程进行分组
Runnable runnable // = ...;
ThreadGroup userGroup = new ThreadGroup("user");
Thread userTask1 = new Thread(userGroup, runnable, "user-task1");
Thread userTask2 = new Thread(userGroup, runnable, "user-task2");
userTask1.start();
userTask2.start();
System.out.println("线程组活跃线程数:" + userGroup.activeCount());
userGroup.list();
线程组还能统一设置组内所有线程的最高优先级,线程单独设置的优先级不会高于线程组设置的最大优先级userGroup.setMaxPriority(Thread.MIN_PRIORITY);
停止线程组内线程不推荐使用stop,使用userGroup.interrupt();
中断线程组内的所有线程
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK