Atomic action cannot stop in the middle: it either happens completely, or it doesn't happen at all. No side effects of an atomic action are visiable until the action is complete.
Java primitive types include: byte; short; int; long; float; double; boolean; char;
讀和寫變量的引用以及primitive types的變量的操作是原子的(除了long和double);
讀和寫任何用volatile關鍵字修飾的變量的操作是原子的(包括long和double);
Primitive 類型并不能完全消除同步錯誤,原子操作有時仍需同步,使用volatile修飾能避免這些錯誤。(用volatile修飾的primitive types)
那么什么時候會發生這種錯誤呢,即在不同線程對primitive類型變量進行賦值時,這種錯誤是可能發生的。(只在不同線程讀取primitive類型變量不會產生這種錯誤)