如何确定管理线程的优先级
Thread提供了几个方法来管理线程的优先级
public static Thread currentThread()
返回对当前正在执行的线程对象的引用。
返回:当前执行的线程。
public final int getPriority()
返回线程的优先级。
返回:该线程的优先级。
public final void setPriority(int newPriority)
更改线程的优先级。
首先调用线程的 checkAccess 方法,且不带任何参数。这可能抛出 SecurityException。
在其他情况下,线程优先级被设定为指定的 newPriority 和该线程的线程组的最大允许优先级相比较小的一个。
参数:
newPriority - 要为线程设定的优先级
抛出:
IllegalArgumentException - 如果优先级不在 MIN_PRIORITY 到 MAX_PRIORITY 范围内。
SecurityException - 如果当前线程无法修改该线程。