java concurrency in practice 读书笔记

In the absence of synchronization, the compiler, processor, and runtime can do some downright weird things to the order in which operations appear to execute. Attempts to reason about the order in which memory actions "must" happen in insufflciently synchronized multithreaded programs will almost certainly be incorrect.
  线程中的非明确同步代码可能会按照非预订的顺序执行

** volatile 变量 要慎用  。 是弱化的的 Synchronized  一般是用来做一些completion, interruption, or status flag。

Locking can guarantee both visibility and atomicity; volatile variables can only guarantee visibility.

你可能感兴趣的:(java,读书)