The Java Memory Model (JMM)

KOTLIN › Concurrency

The rulebook for thread memory sync: visibility, atomicity, ordering, and happens-before.

Thread and memory synchronisation has a searchable name: the Java Memory Model. Each thread may work on its own cached copy of shared data, and the compiler and CPU are allowed to reorder instructions for speed, so one thread's writes are not guaranteed to be seen by another thread, or seen in the order you wrote them. The JMM is the rulebook for when writes become visible. Learn it properly and volatile, synchronized, atomics, locks and ConcurrentHashMap stop being memorised facts and become obvious consequences: they all exist to create happens-before edges.

What this covers

Study this topic

Further reading