Skip to content
Sharp

Java Threading · interview question

In what scenario might a ReentrantLock be preferred over a synchronized block?

Multiple choiceMediumchapter-15-curatedpremiumjava-threadingrace-conditions
Choose one answer
Answer and explanation

Correct answer

D. When you need to try locking without blocking.

Why

ReentrantLock offers more flexibility, such as trying to acquire a lock without blocking, or waiting with a timeout, which can be crucial in complex concurrency scenarios.

Test yourself on Java Threading

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

Start free test
All Java Threading questions →