package com.bjpowernode.demo02;
/**
* 线程的优先级
* 取值范围: 1 ~ 10
* 默认值: 5
* 优先级越高, 被CPU选中的机率越大, 优先级越高获得CPU执行权的机率越大
* t1.setPriority(10); //设置优先级
* @author Administrator
*
*/
public class Test08 {
public static void main(String[] args) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
}
});
t1.setPriority(10); //设置优先级
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
}
});
t2.setPriority(1);
t2.start();
System.out.println( t1.getPriority());
System.out.println( t2.getPriority());
System.out.println( Thread.currentThread().getPriority());
//main线程
for( int i = 1; i <= 200; i++){
System.out.println( Thread.currentThread().getName() + "-->" + i);
}
}
}
java基础回顾之线程--线程的优先级
最新推荐文章于 2021-10-13 22:59:04 发布