Following up on how hardware caches and store buffers break multithreaded code, let’s explore the three standard concurrency tools in Java - volatile, AtomicReference, and synchronized using a real-world scenario.
Running multithreaded software in modern multi-core processor is a physical coordination challenge between the CPU cores, local caches (L1, L2 and L3) and main memory(RAM). Here is what happens inside the machine when threads executes simultaneously.
We write `int age = 25;` and rarely think about what happens in memory. The JVM manages memory for us and gets larger memory regions from the OS when needed. It then allocates space for variables and objects within them. Understanding where data lives and how much memory it uses becomes important when building high-performance, memory-efficient systems.