What is an intrinsic lock (monitor) in Java?
Every object in Java has an associated intrinsic lock, also called a monitor, built into the object header. When a thread enters a synchronized method or a synchronized block, it acquires the intrinsic lock of the relevant object, and only one thread can hold that lock at any given time -- any other thread that tries to acquire the same lock is placed into the BLOCKED state until it becomes available. Intrinsic locks are also reentrant, meaning the same thread that already holds a lock can acquire it again without deadlocking itself, which happens naturally when a synchronized method calls another synchronized method on the same object; the JVM tracks this with a per-thread hold count that increments on each re-acquisition and decrements on each release, only fully releasing the lock once the count reaches zero.
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