| 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
< Prev
Next >

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.

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy