zoukankan      html  css  js  c++  java
  • 笔记20200521002:多线程【线程的优先级】

    package com.chengguo.线程;
    
    /**
     * 测试线程的优先级
     */
    public class Demo_20200519001_Priority {
        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);
            Thread thread6 = new Thread(myPriority);
            //先设置优先级,在启动线程
            thread1.setPriority(3);
            thread1.start();
    
            thread2.start();
    
            thread3.setPriority(1);
            thread3.start();
    
            thread4.setPriority(2);
            thread4.start();
    
            thread5.setPriority(Thread.MAX_PRIORITY);//最大优先级为10
            thread5.start();
    
            thread6.setPriority(7);
            thread6.start();
    
        }
    }
    
    class MyPriority implements Runnable {
    
        @Override
        public void run() {
            //获取线程的名字       测试线程的优先级
            System.out.println(Thread.currentThread().getName() + "--》 优先级为:" + Thread.currentThread().getPriority());
        }
    }
    

      

     
  • 相关阅读:
    Extjs常用的控件
    JasperReport导出
    spring配置连接池
    extjs中xtype类型

    凭什么!
    用心去做,多动脑思考
    闲着无事弄一下荒废已久的博客。。。

    视频下载工具 3.0
  • 原文地址:https://www.cnblogs.com/sadfoo/p/13128681.html
Copyright © 2011-2022 走看看