欢迎光临散文网 会员登陆 & 注册

千里某AndriodFrameWork基础合集+Input专题课【参考】\/--》ccys1473

2023-07-10 12:28 作者:拆字成诗  | 我要投稿

/**

 * 线程优先级

 */

public class Demo22_ThreadPriority{

    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);

        Thread thread5 = new Thread(myPriority);


        //先设置优先级,再启动

        thread1.start();


        thread2.setPriority(1);

        thread2.start();


        thread3.setPriority(4);

        thread3.start();


        thread4.setPriority(Thread.MAX_PRIORITY);//MAX_PRIORITY=10

        thread4.start();


        thread5.setPriority(8);

        thread5.start();

    }

}

class MyPriority implements Runnable{

    @Override

    public void run() {

        System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());

    }

}



千里某AndriodFrameWork基础合集+Input专题课【参考】\/--》ccys1473的评论 (共 条)

分享到微博请遵守国家法律