Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
hard

Java ReentrantLock Concurrency Issue

Mark
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|