java - 为什么ThreadPoolExecutor源码实现中用的是ReentrantLock锁?
PHP中文网
PHP中文网 2017-04-18 10:51:45
0
0
890
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源码实现中大量使用了ReentrantLock 锁,请问为什么使用的是ReentrantLock 锁而不是别的锁机制呢?

PHP中文网
PHP中文网

认证高级PHP讲师

membalas semua(0)
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan