在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;}
是否有任何理由将最终字段复制到局部变量中?
qq_遁去的一_1
白猪掌柜的
相关分类