[concurrency-interest] Stupid Question

javamann at cox.net javamann at cox.net
Tue Feb 12 15:41:47 EST 2013


Stupid question time. While going through the code for an ArrayBlockQueue I came across numerous instances where the instance 'lock' is copied to a variable in a Method. I know there is a reason for this, I just don't know what it is.

Thanks

-Pete

    public int remainingCapacity() {
        final ReentrantLock lock = this.lock;
        lock.lock();
        try {
            return items.length - count;
        } finally {
            lock.unlock();
        }
    }



More information about the Concurrency-interest mailing list