Java ReentrantLock Concurrency Issue
Consider the LockExample class shown below. What is the most likely concurrency issue to result from the omission in the doWork method?
import java.util.concurrent.locks.ReentrantLock;
public class LockExample {
private ReentrantLock lock = new ReentrantLock();
public void doWork() {
lock.lock();
try {
// perform operations
doMoreWork();
} finally {
// Missing unlock here
}
}
public void doMoreWork() {
lock.lock();
try {
// additional operations
} finally {
lock.unlock();
}
}
}
A
An InterruptedException that stops the thread unexpectedly.
B
A potential deadlock due to the failure to release the lock acquired in doWork(), preventing subsequent acquisitions.
C
A race condition in the execution of doMoreWork() because of overlapping lock usage.
D
A compile-time error because of missing lock management code.
Question Leaderboard
Not enough data yet to show leaderboard.
