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

      

     
  • 相关阅读:
    01 WEB白帽子Python入门
    07 SSRF漏洞
    JAVA基础学习day04--IDEA、方法
    一些常用的计算机快捷指令
    记录一次xss平台的安装
    upload-labs
    蓝队防护基础
    bagecms的代码审计
    window入侵排查基本
    常用端口总结
  • 原文地址:https://www.cnblogs.com/sadfoo/p/13128681.html
Copyright © 2011-2022 走看看