package cn.thread2;
/**
* 测试线程优先级
* MAX_PRIORITY=10
* MIN_PRIORITY=1
* NORM_PRIORITY=5
* 数值只代表概率,数值大不一定保证优先执行
* @author Chill Lyn
*
*/
public class TestPriority implements Runnable {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + ":" + Thread.currentThread().getPriority());
}
public static void main(String[] args) {
TestPriority tp = new TestPriority();
Thread t1 = new Thread(tp, "t1");
Thread t2 = new Thread(tp, "t2");
Thread t3 = new Thread(tp, "t3");
Thread t4 = new Thread(tp, "t4");
Thread t5 = new Thread(tp, "t5");
Thread t6 = new Thread(tp, "t6");
t1.setPriority(Thread.MAX_PRIORITY);
t2.setPriority(Thread.MAX_PRIORITY);
t5.setPriority(Thread.MIN_PRIORITY);
t6.setPriority(Thread.MIN_PRIORITY);
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
t6.start();
}
}
结果参考