• 17.Priority优先级


    /**
     * 优先级
     */
    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
    
    }
    
  • 相关阅读:
    Spring4
    Mysql索引优化、JMM内存模型
    深入浅出JVM
    ZGC垃圾搜集器
    Hibernate4基础
    红楼梦 各版本及资料
    JavaME环境配置
    5.1 Intent
    4.3 异步任务
    4.2.2 网络编程之Socket
  • 原文地址:https://www.cnblogs.com/fly-book/p/11383759.html
Copyright © 2020-2023  润新知