How has volatile changed in recent Java versions?

In recent Java versions, the behavior and understanding of the `volatile` keyword have been clarified. The `volatile` keyword ensures that reads and writes to a variable are visible to all threads, providing a lighter alternative to synchronization for certain use cases. However, it does not guarantee atomicity. As Java has evolved, the importance of memory visibility and its implications in concurrent programming have been emphasized, leading to a better comprehension of when and how to use `volatile` effectively.
volatile keyword, Java concurrency, memory visibility, multithreading, Java 5 and newer
        class VolatileExample {
            private volatile boolean running = true;

            public void run() {
                while (running) {
                    // Do something
                }
            }

            public void stop() {
                running = false; // The change will be visible to the run() method
            }
        }
        

volatile keyword Java concurrency memory visibility multithreading Java 5 and newer