java并发编程

Greg Mattes推荐的介绍并发编程的书Java Concurrency in Practice

volatile 的语义:“… the volatile modifier guarantees that any thread that reads a field will see the most recently written value.”- Josh Bloch

这意味着,对于被声明为volatile的域,当写操作发生时,所有的读操作都会看到这个change,既然有局部缓存存在。

当一个域被synchronized 方法或代码块 guarded 的时候,就没必要把一个域声明为volatile了,因为synchronized同样会保证上面的效果。

posted @ 2013-11-22 20:03  ridox  阅读(178)  评论(0编辑  收藏  举报