关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

Java连载:线程优先级

发布时间:2020-04-02 00:00:00

一、线程的优先级

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/

 


/template/Home/Zkeys/PC/Static