Simplest and understandable example of volatile keyword in Java
问题 I'm reading about volatile keyword in Java and completely understand the theory part of it. But, what I'm searching for is, a good case example, which shows what would happen if variable wasn't volatile and if it were. Below code snippet doesn't work as expected (taken from here): class Test extends Thread { boolean keepRunning = true; public void run() { while (keepRunning) { } System.out.println("Thread terminated."); } public static void main(String[] args) throws InterruptedException {