private boolean addIfUnderCorePoolSize(Runnable firstTask) {
Thread t = null;
final ReentrantLock mainLock = this.mainLock;
mainLock.lock();
try {
if (poolSize < corePoolSize && runState == RUNNING)
t = addThread(firstTask);
} finally {
mainLock.unlock();
}
if (t == null)
return false;
t.start();
return true;
}
ThreadPoolExecutor源碼實(shí)現(xiàn)中大量使用了ReentrantLock 鎖,請(qǐng)問(wèn)為什么使用的是ReentrantLock 鎖而不是別的鎖機(jī)制呢?
為什么ThreadPoolExecutor源碼實(shí)現(xiàn)中用的是ReentrantLock鎖?
30秒到達(dá)戰(zhàn)場(chǎng)
2019-03-01 11:05:57