One keyword - synchronized - and two threads stop corrupting each other's data. But what did the keyword actually buy you? The JVM spec has a surprisingly small answer: one mechanism, the monitor, and a handful of bytecode instructions. Let's open it up with real javap output, a live look at a blocked thread, and the Linux primitive the JVM leans on when a thread truly has to wait.
One construct: the monitor
The JVM spec ( JVMS 2.11.10 ) is blunt: "The Java Virtual Machine supports synchronization of both methods and sequences of instructions within a method by a single synchronization construct: the monitor."
Every object can act as a monitor. synchronized (lock) { ... } means: enter the monitor associated with lock ; only one thread can own it at a time; everyone else waits.…