2017-03-13 Java多线程学习笔记-Doug Lea 谈 Synchronization and the Java Memory Model

Doug Lea 谈 Synchronization and the Java Memory Model

主要是讨论同步和Java内存模型之间的关系,讲的原理,从多线程处理产生的问题出发,引导出同步的三个需要处理的问题:原子性,可见性,顺序性。

Atomicity

Which instructions must have indivisible effects. For purposes of the model, these rules need to be stated only for simple reads and writes of memory cells representing fields - instance and static variables, also including array elements, but not including local variables inside methods.

Visibility

Under what conditions the effects of one thread are visible to another. The effects of interest here are writes to fields, as seen via reads of those fields.

Ordering

Under what conditions the effects of operations can appear out of order to any given thread. The main ordering issues surround reads and writes associated with sequences of assignment statements.

讲的特别棒,虽然英文吃力,但是有所得。

然后 Lea 还特别讲了下 Java 关键字 Volatile,用到的场景:

The field need not obey any invariants with respect to others.
Writes to the field do not depend on its current value.
No thread ever writes an illegal value with respect to intended semantics.
The actions of readers do not depend on values of other non-volatile fields.

你可能感兴趣的:(2017-03-13 Java多线程学习笔记-Doug Lea 谈 Synchronization and the Java Memory Model)