码迷,mamicode.com
首页 > 其他好文 > 详细

17.Priority优先级

时间:2019-08-20 16:41:36      阅读:69      评论:0      收藏:0      [点我收藏+]

标签:let   break   ide   main   com   ati   over   complete   read   

/**
 * 优先级
 */
public class PriorityDemo {
    public static class HightPriority extends Thread{
        static int count = 0;

        @Override
        public void run() {
            while (true){
                synchronized (PriorityDemo.class){
                    count++;
                    if (count>100000000){
                        System.out.println("HightPriority is complete");
                        break;
                    }
                }
            }
        }
    }
    public static class LowPriority extends Thread{
        static int count = 0;

        @Override
        public void run() {
            while (true){
                synchronized (PriorityDemo.class){
                    count++;
                    if (count>100000000){
                        System.out.println("LowPriority is complete");
                        break;
                    }
                }
            }
        }
    }
    public static void main(String[] args){
        HightPriority hightPriority = new HightPriority();
        LowPriority lowPriority = new LowPriority();
        hightPriority.setPriority(Thread.MAX_PRIORITY);//高优先级
        lowPriority.setPriority(Thread.MIN_PRIORITY);//低优先级
        lowPriority.start();
        hightPriority.start();
    }
    //HightPriority is complete
    //LowPriority is complete

}

17.Priority优先级

标签:let   break   ide   main   com   ati   over   complete   read   

原文地址:https://www.cnblogs.com/fly-book/p/11383759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!