每个线程都有自己的优先级,优先级越高的线程得到CPU的分配的执行时间越多
默认优先级是5,范围从1到10。
public class Priority {
public static void main(String[] args) {
Thread t1 = new Thread(new T1());
Thread t2 = new Thread(new T2());
t1.setPriority(Thread.NORM_PRIORITY+3);
t1.start();
t2.start();
}
}
class T1 implements Runnable{
public void run(){
for(int i =0 ; i<1000;i++){
System.out.println("T1: " +i);
}
}
}
class T2 implements Runnable{
public void run(){
for(int i =0 ; i<1000;i++){
System.out.println("---------------T2: " +i);
}
}
}