Java ReentrantLock Concurrency Issue
What concurrency issue is most likely caused by 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
A race condition in the execution of doMoreWork() because of overlapping lock usage.
B
A potential deadlock due to the failure to release the lock acquired in doWork(), preventing subsequent acquisitions.
C
A compile-time error because of missing lock management code.
D
An InterruptedException that stops the thread unexpectedly.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE