A problem about Java BlockingQueue source code learning

first attach the BlockingQueue source code take () code:

public class ArrayBlockingQueue<E> implements BlockingQueue<E> {

    final ReentrantLock lock;

    //lock
    public ArrayBlockingQueue<E>(){
        //...
    }
    public E take() throws InterruptedException {
        final ReentrantLock lock = this.lock;  //
        lock.lockInterruptibly();
        try {
            while (count == 0)
                notEmpty.await();
            return dequeue();
        } finally {
            lock.unlock();
        }
    }

}

Why does the first line final ReentrantLock lock = this.lock, in the take method copy the global field lock to a local variable first? Is it not possible to use global final lock directly (eg.) This.lock.lockInterruptibly ())?? Why bother?


There is the same question on

stackoverflow .

.copying to locals produces the smallest bytecode, and for low-level code it's nice to write code that's a little closer to the machine

it's too low-level. Ignore it


copy in to reduce the cost of "getting fields".
it's a squeeze performance

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e0eb-2c3f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e0eb-2c3f7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?