Course contentsShow
← Java
Lesson 2653 of 2,87049. Synchronization and LockingFree lesson

The Implicit Lock (Monitor) of an Object

Every Java object has an intrinsic lock (monitor) that synchronized methods acquire and release automatically.

The Implicit Lock (Monitor) of an Object

You'll learn that every Java object carries a hidden lock used to control synchronized access.

What Is the Implicit Lock?

Every single object in Java—whether it's a String, ArrayList, your custom class instance, or even a plain Object—has an intrinsic lock (also called a monitor) built into it. You can't see it in the object's fields, and you didn't declare it explicitly. The JVM manages it automatically.

When you mark a method with the synchronized keyword, that method acquires the object's implicit lock when it starts executing and releases it when it finishes (either normally or by throwing an exception). Only one thread can hold an object's lock at any given time.

How It Works

Think of the implicit lock like a key to a single-occupancy restroom. The restroom (the object) has exactly one key attached to it. When a thread wants to execute a synchronized method on that object, it must first grab the key. If another thread already has it, the first thread must wait. When the method finishes, the key is automatically returned.

For instance methods, the lock belongs to the specific object instance (this). For static synchronized methods (not yet covered), the lock belongs to the Class object itself.

Why This Matters

The automatic acquire-and-release behavior is what makes synchronized methods safe from race conditions. You don't manually lock or unlock anything—the JVM handles it. This prevents multiple threads from executing synchronized methods on the same object simultaneously, protecting shared state from corruption.

Key Takeaway:
Every Java object has an implicit lock (monitor) that synchronized methods automatically acquire on entry and release on exit, ensuring only one thread can execute synchronized code on that object at a time.