首页 > 编程语言 > 详细

Java多线程(priority)

时间:2021-08-14 16:49:51      阅读:20      评论:0      收藏:0      [点我收藏+]
线程的优先级
//测试线程优先级
public class TestPriority {
    public static void main(String[] args) {
        //主线程优先级
        System.out.println(Thread.currentThread().getName()+"---"+Thread.currentThread().getPriority());
        MyPriority myPriority=new MyPriority();

        Thread t1 =new Thread(myPriority);
        Thread t2 =new Thread(myPriority);
        Thread t3 =new Thread(myPriority);
        Thread t4 =new Thread(myPriority);
        //先设置优先级
        t1.start();

        t2.setPriority(1);
        t2.start();

        t3.setPriority(4);
        t3.start();

        t4.setPriority(Thread.MAX_PRIORITY);//MAX_PRIORITY=10
        t4.start();

    }
}

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

 

Java多线程(priority)

原文:https://www.cnblogs.com/ooo926/p/15140835.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!