javaSE之多线程之优先级

package state;

public class TestPriority {
    
    


    //主线程默认优先级
    public static void main(String[] args) {
    
    
        System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());

        MyPriority priority = new MyPriority();
        Thread t1 = new Thread(priority);
        Thread t2 = new Thread(priority);
        Thread t3 = new Thread(priority);
        Thread t4 = new Thread(priority);

        t1.start();

        t2.setPriority(10);

        t2.start();
        t3.setPriority(8);

        t3.start();
        t4.setPriority(7);
        t4.start();

    }
}


class MyPriority implements Runnable{
    
    


    @Override
    public void run() {
    
    
        System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
    }
}



猜你喜欢

转载自blog.csdn.net/qq_42794826/article/details/108957099
今日推荐