package test.Thread;
public class testPriority {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t1 = new Thread(new R1());
Thread t2 = new Thread(new R2());
t1.setPriority(Thread.NORM_PRIORITY+5);
t1.start();
t2.start();
}
}
class R1 implements Runnable {
public void run() {
// TODO Auto-generated method stub
for (int i = 1; i < 20; i++) {
System.out.println("-----R1");
}
}
}
class R2 implements Runnable {
public void run() {
// TODO Auto-generated method stub
for (int i = 1; i < 20; i++) {
System.out.println("R2");
}
}
}
The result of not set priority:
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
-----R1
-----R1
-----R1
-----R1
-----R1
-----R1
-----R1
-----R1
R2
R2
R2
R2
R2
R2
R2
R2
R2
The result of set priority:
-----R1
R2
-----R1
-----R1
-----R1
-----R1
-----R1
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
-----R1
R2
R2
R2
R2
R2
R2