Skip to main content

Synchronization in Java

Learn Synchronization in Java (Multithreading&Multitasking, Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

1. Introduction Synchronization controls access to shared data so only one thread at a time runs a critical section. It is written with the synchronized keyword on a method or block, using the hidden monitor lock every object has, and sits on a scale with volatile , atomics , ReentrantLock and StampedLock . The Java Memory Model guarantees that an unlock happens before the next lock of the same monitor , which makes writes visible.

More lessons in Multithreading&Multitasking