2008-02-23
保持java线程间可见性的5种方式
| Primitive | Writes up to and including… | ...are made visible to… |
|---|---|---|
| Object | the end of a synchronized block or method | a thread entering a synchronized block or method for the same object. |
| Volatile field | a write to a volatile field | any thread reading that volatile field. |
| Thread | a call to Thread.start | the newly started thread. |
| Thread | the final write made by a dying thread | any thread which successfully calls Thread.join on that thread. |
| Final field | the initialization of a final field (but only those writes affecting the field and any object it references) | any thread, provided that the constructor of the object containing the field doesn’t write the value of this anywhere eventually visible to other threads |
这些在《java并发编程实践》一书中已经有详细解释,特别是对于ReentrantLock、volatile域以及final域的讨论。今天在MenTaLguY的blog上看到这张表,摘录下。
发表评论
我的留言簿
-
你好,看过你关于自定义classloader的回帖,想问问几个问题:
  ...
-- by llp20_2000
最近加入圈子
最新评论
-
Ruby Tip——读文件
花花公子 写道IO.read("test.log")嗯,这个方法我是知道的,我前 ...
-- by dennis_zane -
Ruby Tip——读文件
IO.read("test.log")
-- by 花花公子 -
一封邮件
咋我没收到呢....
-- by yangzhihuan -
漂亮的代码
说得比较深.看的时候,觉得句句都正中心坎.看完之后,好像没啥收获.还是要自己试过 ...
-- by yangzhihuan -
广州opensource camp小记
貌似你那件open source camp的T-shirt背后很多广告滴说.
-- by yangzhihuan







评论排行榜