Skip to content
Sharp

Concurrency basics · interview question

How can you avoid deadlocks when using multiple ReentrantLocks in a method?

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

Correct answer

B. By always acquiring the locks in a consistent order.

Why

To avoid deadlocks, it's important to acquire multiple locks in a consistent order throughout the application. This ensures that threads do not end up in a situation where they are waiting on each other indefinitely.

Test yourself on Concurrency basics

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

Start free test
All Concurrency basics questions →