线程优先级
-
NORM_PRIORITY=5
-
MAX_PRIORITY=10
-
MIN_PRIORITY=1
package com.kaka.thread;
public class TestPriority implements Runnable{
public static void main(String[] args) {
//主线程main默认优先级为5
System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
TestPriority testPriority=new TestPriority();
Thread t1=new Thread(testPriority,"t1");
Thread t2=new Thread(testPriority,"t2");
Thread t3=new Thread(testPriority,"t3");
Thread t4=new Thread(testPriority,"t4");
Thread t5=new Thread(testPriority,"t5");
//先设置优先级再启动
t1.start();//默认优先级是5
t2.setPriority(1);
t2.start();
t5.setPriority(Thread.MAX_PRIORITY);//最大优先级为10
t5.start();
t3.setPriority(3);
t3.start();
t4.setPriority(8);
t4.start();
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
}
}