...
Declaring a variable volatile
guarantees the happens-before relationship so that writes are always visible to subsequent reads from any thread. It also ensures sequential consistency, in that, volatile reads read and writes write operations cannot be reordered with respect to each other and in addition, as required by the modern JMM, volatile read and write operations are also not reordered with respect to operations on non-volatile variables.
...