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

    }

  }

}

Java连载105-线程的优先级_第1张图片

三、源码:

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

 Java连载105-线程的优先级_第2张图片

 

你可能感兴趣的:(Java连载105-线程的优先级)