1. AtomicReference - Object Swapping
The Concept: While AtomicInteger works for primitives, AtomicReference<V> allows you to update a reference to an entire object as a single atomic unit. This is the foundation of “Immutable State” updates. import java.util.concurrent.atomic.AtomicReference; public class ConfigManager { // A shared configuration object that many threads read private final AtomicReference<Config> currentConfig = new AtomicReference<>(new Config("v1")); public void updateConfig(String newVersion) { Config oldConfig; Config newConfig = new Config(newVersion); do { oldConfig = currentConfig.get(); // Snapshot of the pointer // We don't modify oldConfig; we create a whole new one! } while (!currentConfig.compareAndSet(oldConfig, newConfig)); System.out.println("Config updated to: " + newVersion); } } class Config { final String version; Config(String v) { this.version = v; } } Explanation: ...