fullyLock()
contains 2 locks:putLock and takeLock, they are all ReentrantLock
and NonfairSync
void fullyLock() {
putLock.lock();
takeLock.lock();
}
Will there be such a situation :
In remove()
method, putLock.lock()
success, takeLock.lock()
throw exception, then the current thread will always hold putLock
, other thread will never be able to operate this LinkedBlockingQueue.
- Is it possible that such a problem may occur?
- If it is not possible, why?
- If possible, what can jdk or us do something to remedy it?
remove()
code:
public void remove() {
if (lastRet == null)
throw new IllegalStateException();
fullyLock();
try {
Node<E> node = lastRet;
lastRet = null;
for (Node<E> trail = head, p = trail.next;
p != null;
trail = p, p = p.next) {
if (p == node) {
unlink(p, trail);
break;
}
}
} finally {
fullyUnlock();
}
}