Why a Java Volatile Example May Terminate Without Volatile
The program that loops on a non‑volatile boolean flag sometimes terminates because changing the counter to a volatile int or to an Integer causes the JVM to emit hidden memory barriers on reference writes, making the flag visible, but this behavior is JVM‑specific and not a reliable substitute for declaring the flag volatile.