Skip to content
Sharp

Concurrency basics · interview question

Why is it important to release a ReentrantLock in a finally block?

Multiple choiceHardchapter-15-curatedpremiumconcurrencysynchronized-and-locks
Choose one answer
Answer and explanation

Correct answer

C. To ensure the lock is released even if an exception occurs

Why

ReentrantLocks must be manually released, and if an exception is thrown, failing to release the lock could lead to deadlocks. Using a finally block ensures that the lock is released regardless of how the try block is exited.

Test yourself on Concurrency basics

A free test with instant, explained results. No account needed.

Start free test
All Concurrency basics questions →