Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1585839
  • 博文数量: 399
  • 博客积分: 8508
  • 博客等级: 中将
  • 技术积分: 5302
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-14 09:28
个人简介

能力强的人善于解决问题,有智慧的人善于绕过问题。 区别很微妙,小心谨慎做后者。

文章分类

全部博文(399)

文章存档

2018年(3)

2017年(1)

2016年(1)

2015年(69)

2013年(14)

2012年(17)

2011年(12)

2010年(189)

2009年(93)

分类: 架构设计与优化

2015-05-02 16:28:41

Java 内存模型

The JMM defines a partial ordering called happens-before on all actions within the program.

The rules for happens-before are:

  • Program order rule. Each action in a thread happens-before every action in that thread that comes later in the program order.
  • Monitor lock rule. An unlock on a monitor lock happens-before every subsequent lock on that same monitor lock.[3]
  • Volatile variable rule. A write to a volatile field happens-before every subsequent read of that same field.[4]
  • Thread start rule. A call to Thread.start on a thread happens-before every action in the started thread.
  • Thread termination rule. Any action in a thread happens-before any other thread detects that thread has terminated, either by successfully return from Thread.join or by Thread.isAlive returning false.
  • Interruption rule. A thread calling interrupt on another thread happens-before the interrupted thread detects the interrupt (either by having InterruptedException tHRown, or invoking isInterrupted or interrupted)
  • Finalizer rule. The end of a constructor for an object happens-before the start of the finalizer for that object.
  • Transitivity. If A happens-before B, and B happens-before C, then A happens-before C.
注意
Locks and unlocks on explicit Lock objects have the same memory semantics as intrinsic locks.
Reads and writes of atomic variables have the same memory semantics as volatile variables.
阅读(1078) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~