I wonder why we can see this type of code pattern in java.util.concurrent classes:
public class ArrayBlockingQueue...
...
final ReentrantLock lock;
...
public boolean offer(E e) {
checkNotNull(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
...
} finally {
lock.unlock();
}
}
I don't understand why we must copy the reference to the lock before we call the lock() and unlock() method as the lock attribute is final.
Thanks for your help,
Romain.