1

Possible Duplicate:
In ArrayBlockingQueue, why copy final member field into local final variable?

Check out this code from ThreadPoolExecutor:

private final ReentrantLock mainLock = new ReentrantLock();

...

private void ensureQueuedTaskHandled(Runnable command) {
        final ReentrantLock mainLock = this.mainLock;
        mainLock.lock();

Why is this.mainLock copied to a local variable? I know this pattern is useful to ensure the field doesn't change, but we're talking about a final field here. Is it still relevant?

Community
  • 1
  • 1
ripper234
  • 222,824
  • 274
  • 634
  • 905

0 Answers0