VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > 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

 

出  处:https://www.cnblogs.com/ruigege0000/p/12616995.html


相关教程