package com.kuang.Demo05;
//测试线程的优先级
public class TestPriority {
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
MyPriority myPriority = new MyPriority();
Thread thread0 = new Thread(myPriority, "0号线程");
Thread thread1 = new Thread(myPriority, "1号线程");
Thread thread2 = new Thread(myPriority, "2号线程");
Thread thread3 = new Thread(myPriority, "3号线程");
Thread thread4 = new Thread(myPriority, "4号线程");
thread0.start();
thread1.setPriority(3);
thread1.start();
thread2.setPriority(1);
thread2.start();
thread3.setPriority(Thread.MAX_PRIORITY);
thread3.start();
thread4.setPriority(8);
thread4.start();
}
}
class MyPriority implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
}
}
优先级设置需要放在start()前面.
性能倒置