zoukankan      html  css  js  c++  java
  • Java连载105-线程的优先级

    一、线程的优先级

    1.线程优先级的获取的CPU时间片会相对多一点

    (1)优先级为1-10

    (2)最低为1

    (3)最高为10

    (4)默认为5

    package com.bjpowernode.java_learning;
    
    ​
    
    public class D105_1_PriorotyOfMultithread {
    
      public static void main(String[] arsg) {
    
       
    
        System.out.println(Thread.MAX_PRIORITY);
    
        System.out.println(Thread.MIN_PRIORITY);
    
        System.out.println(Thread.NORM_PRIORITY);
    
        System.out.println("=================");
    
       
    
        Thread t1 = new Processor105();
    
        t1.setName("t1");
    
       
    
        Thread t2 = new Processor105();
    
        t2.setName("t2");
    
       
    
        System.out.println(t1.getPriority());
    
        System.out.println(t2.getPriority());
    
       
    
        //设置优先级
    
        t1.setPriority(5);
    
        t2.setPriority(4);
    
       
    
        t1.start();
    
        t2.start();
    
      }
    
    }
    
    ​
    
    class Processor105 extends Thread{
    
      public void run() {
    
        for(int i=0;i<5;i++) {
    
          System.out.println(Thread.currentThread().getName()+"--->"+i);
    
        }
    
      }
    
    }

    三、源码:

    D105_1_PriorotyOfMultithread.java

    https://github.com/ruigege66/Java/blob/master/D105_1_PriorotyOfMultithread.java

    2.CSDN:https://blog.csdn.net/weixin_44630050

    3.博客园:https://www.cnblogs.com/ruigege0000/

    4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料

     

  • 相关阅读:
    网站链接
    CSS 初始化
    常见浏览器+浏览器内核
    sublime及其插件的安装
    数码时钟.js
    每天迁移MySQL历史数据到历史库Python脚本
    python和redis简单交互
    python和mongodb简单交互
    python3与mysql交互
    Red Hat Enterprise Linux 7.2修改主机名(hostname)
  • 原文地址:https://www.cnblogs.com/ruigege0000/p/12616995.html
Copyright © 2011-2022 走看看