线程优先级Priority

public class TestThreadPriority {

public static void main(String[] args) {
System.out.println(Thread.currentThread().getName()+"-->的优先级是"+Thread.currentThread().getPriority());

MyPriority myPriority = new MyPriority();
Thread thread1 = new Thread(myPriority,"小明");
Thread thread2 = new Thread(myPriority,"小红");
Thread thread3 = new Thread(myPriority,"小黄");
Thread thread4 = new Thread(myPriority,"小绿");

thread1.setPriority(Thread.MAX_PRIORITY);
thread1.start();
thread2.setPriority(Thread.MIN_PRIORITY);
thread2.start();
thread3.setPriority(5);
thread3.start();
thread4.setPriority(2);
thread4.start();
}
}
class MyPriority implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"-->的优先级是"+Thread.currentThread().getPriority());
}
}

上一篇:priority_queue优先队列


下一篇:android: 详解 Android 中的 HandlerThread(转)