当前位置: 移动技术网 > IT编程>开发语言>Java > Java连载105-线程的优先级

Java连载105-线程的优先级

2020年04月02日  | 移动技术网IT编程  | 我要评论

徐守盛与徐向前,花样少女是多大,李庆民

一、线程的优先级

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

 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网