package com.ajax;
//线程的优先级
public class Example03 {
public static void main(String[] args){
Thread minPriority=new Thread(new MinPriority(),"优先级较低的线程");
Thread maxPriority=new Thread(new MaxPriority(),"优先级较高的线程");
minPriority.setPriority(Thread.MIN_PRIORITY);//设置线程的优先级
maxPriority.setPriority(Thread.MAX_PRIORITY);
maxPriority.setPriority(10);
//开启两个线程
maxPriority.start();
minPriority.start();
}
}
class MinPriority implements Runnable{
public void run(){
for(int i=0;i<10;i++){
System.out.println(Thread.currentThread().getName()+"正在输出:"+i);
}
}
}
class MaxPriority implements Runnable{
public void run(){
for(int i=0;i<10;i++){
System.out.println(Thread.currentThread().getName()+"正在输出"+i);
}
}
}
线程的优先级
最新推荐文章于 2020-10-01 22:30:54 发布