volatile:声明一个共享变量,如:class VolatileVar{volatile int volatileV;……}由多个并发线程共享的变量可以用volatile来修饰,使得各个线程对该变量的访问能保持一致,(目前Java运行时系统忽视这一限定)。
解决方案 »
- POI无法提取出word2007中的图片吗
- 请教关于java类间调用的问题
- 谁用Jericho HTML Parser,看看Source的public Element findNextElement(int pos, java.lang.String name)方法
- 招聘java开发工程师
- 谈谈用JAVA业验证邮箱是否有效的验证
- 请教
- j2sdk1.4.2安装问题,已经搜索过,不知道怎么解决
- 在哪里可以上载到jbuilder最新版?
- 请教怎样调用struts中html tag中的 select tag的例如onclick,onchange事件
- 你是否可以回答Socket的问题?数据先后问题
- 一个很弱的问题:用JDK1.2如何编译java文件
- 我的tomcat为什么不认汉字的文件名啊
A field may be declared volatile, in which case a thread must reconcile its working copy of the field with the master copy every time it accesses the variable. Moreover, operations on the master copies of one or more volatile variables onbehalf of a thread are performed by the main memory in exactly the order that the thread requested.
后一句意义很重要,如果有多个volatail变量,当多个线程都操作和访问它们时,如果每个线程访问的顺序是同样的,就能达到synchronized的效果。