//线程优先级
//不一定起作用
//优先级 1-10,超出范围则报错
//默认优先级为5

package state;

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 testPriority = new TestPriority();

        Thread t1 = new Thread(testPriority);
        Thread t2 = new Thread(testPriority);
        Thread t3 = new Thread(testPriority);
        Thread t4 = new Thread(testPriority);
        Thread t5 = new Thread(testPriority);
        Thread t6 = new Thread(testPriority);

//        设置优先级
        t1.setPriority(1);
        t2.setPriority(6);
        t3.setPriority(5);
        t4.setPriority(10);
        t5.setPriority(1);


        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
        t6.start();
    }
}

在这里插入图片描述