线程的优先级
作者:互联网
package 多线程练习;
public class Thread优先级 {
public static void main(String[] args) {
Runnable runnable = () -> {
System.out.println("线程名:" + Thread.currentThread().getName() + " <-> 优先级:" + Thread.currentThread().getPriority());
};
// 装载线程
Thread t1 = new Thread(runnable, "t1");
Thread t2 = new Thread(runnable, "t2");
Thread t3 = new Thread(runnable, "t3");
Thread t4 = new Thread(runnable, "t4");
Thread t5 = new Thread(runnable, "t5");
// 设置优先级的大小 具体实际优先级看CPU的调度 设置还是能代表一定的优先权重
t1.setPriority(Thread.MIN_PRIORITY);
t1.start();
t2.setPriority(2);
t2.start();
t3.setPriority(3);
t3.start();
t4.start();
t5.setPriority(Thread.MAX_PRIORITY);
t5.start();
}
}
标签:runnable,优先级,Thread,t5,start,线程,new 来源: https://www.cnblogs.com/wooroc/p/15807237.html