在ArrayBlockingQueue中,为什么要将最终成员字段复制到局部变量中?在……里面ArrayBlockingQueue,所有需要锁的方法都将其复制到本地。final变量,然后调用lock().public boolean offer(E e) {
if (e == null) throw new NullPointerException();
final ReentrantLock lock = this.lock;
lock.lock();
try {
if (count == items.length)
return false;
else {
insert(e);
return true;
}
} finally {
lock.unlock();
}}有什么理由复制this.lock到局部变量lock当田野this.lock是final?此外,它还使用E[]在采取行动之前:private E extract() {
final E[] items = this.items;
E x = items[takeIndex];
items[takeIndex] = null;
takeIndex = inc(takeIndex);
--count;
notFull.signal();
return x;}是否有任何理由将最终字段复制到局部变量中?
添加回答
举报
0/150
提交
取消