beginnerFoundations

What does it mean for a lock to be reentrant?

A lock is reentrant if a thread that already holds it is allowed to acquire it again without deadlocking itself. Both Java's intrinsic locks used by the synchronized keyword and the explicit ReentrantLock class are reentrant, and the JVM implements this by tracking a per-thread hold count: each time the owning thread re-acquires the lock the count goes up, and each unlock call decrements it, with the lock only becoming fully available to other threads once the count returns to zero. Reentrancy matters in practice because without it, something as ordinary as a synchronized method calling another synchronized method on the same object would deadlock the calling thread against itself, since it would already own the lock and yet be forced to wait to acquire it again.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What is a ThreadLocal, and when would you use one?← Back to all Java Concurrency & Multithreading questions