Synchronized and Volatile

Back to Java Concurrency

Java’s built-in synchronization primitives. synchronized provides mutual exclusion and memory visibility (monitor pattern). volatile ensures that reads and writes to a variable are always visible to all threads (prevents caching in registers) but does not provide atomicity for compound operations.

concurrency language-specific java synchronized volatile