优先级

xiaoxiao2021-02-28  33

线程优先级设置:setPriority(int  value) 括号参数是1-10级别。1代表最低级别,10代表最高级别。小于1或大于10,会抛出IllegalArgumentException异常。

JDK源代码优先级定义如下:

public final void setPriority(int newPriority) { ThreadGroup g; checkAccess(); if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) { throw new IllegalArgumentException(); } if((g = getThreadGroup()) != null) { if (newPriority > g.getMaxPriority()) { newPriority = g.getMaxPriority(); } setPriority0(priority = newPriority); } }
转载请注明原文地址: https://www.6miu.com/read-2350121.html

最新回复(0)