java volatile 可见行(Visibility),原子性(Atomicity),有序性(Ordering)

Saw a very good Chinese article explaining Visibility/Atomicity/Ordering for the volatile keyword.  From HERE. Summary is Volatile provides visibility and ordering but not atomicity. Locking guarantees atomicity, visibility and ordering. So volatile is not a substitute for synchronization. HERE is another article from one of the jsr-133 author written back in 2007 but still very informative. 一、Java内存模型 想要理解volatile为什么能确保可见性,就要先理解Java中的内存模型是什么样的。…