线程的优先级设置
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);//高优先级
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);//低优先级
设置优先级时应该通过currentThread()来获取当前的Thread对象,以此Thread对象调用
public final void setPriority(int newPriority)来设置优先级;
其中,参数 newPriority介于10~1之间,因为
java.lang.Thread | ||
---|---|---|
public static final int | MAX_PRIORITY | 10 |
public static final int | MIN_PRIORITY | 1 |
public static final int | NORM_PRIORITY | 5 |
否则抛出错误