java 线程优先级有10个等级
(int 1 ,2,3,4,5,6,7,8,9,10)
MAX_PRIORITY=10 最大
MIN_PRIORITY=0 最小
NORM_PRIORITY = 5; 线程 默认
public int getPriority()
public void setPriority(int newPriority);
定义一个 继承 Thread类的接口
class MyThreed extends Thread{
private String name;
public MyThreed(String name) {
this.name =name;
}
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 10; i++) {
System.out.println("线程 ---- "+name+"正在运行");
}
**Thread.currentThread().setPriority(2);** //设置优先级
System.out.println(Thread.currentThread().getPriority()); //获取优先级
}
}