今天重扫了corejava 14 并发的一章,在谈到volatile域代替synchronized 应用于并发更新时,看到如下内容,并发更新可用内部锁的方式但会带来阻塞问题,可用volatile域替代。个人发觉好像有哪里欠了点逻辑,似乎volatile域为什么能替代内部锁并没有讲明原因。秉承着疑惑对了一下原版。

果然在原版中多了这么一句解释:

The compiler will insert the appropriate code to ensure that a change to the done
variable in one thread is visible from any other thread that reads the variable.

编译器会插入相应的代码以保证一个线程的值完成的改变情况对其它线程是可见的。

这对应着上文的一下两点的问题的解决(如下图):

一、计算机多线程高速缓存同步的问题

二、java编译器指令重排问题

二者都会导致在多线程环境下变量值不同步。

在使用volatile后,可使变量变化后的状态即时可见,可代替原子操作的锁

Core.Java.Volume.I.Fundamentals.10th.Edition 14.5.8 Volatile域 中文版 章节勘误的更多相关文章

  1. Core Java Volume I — 1.2. The Java "White Paper" Buzzwords

    1.2. The Java "White Paper" BuzzwordsThe authors of Java have written an influential White ...

  2. Core Java Volume I — 4.7. Packages

    4.7. PackagesJava allows you to group classes in a collection called a package. Packages are conveni ...

  3. Core Java Volume I — 3.10. Arrays

    3.10. ArraysAn array is a data structure that stores a collection of values of the same type. You ac ...

  4. Core Java Volume I — 4.10. Class Design Hints

    4.10. Class Design HintsWithout trying to be comprehensive or tedious, we want to end this chapter w ...

  5. Core Java Volume I — 3.8. Control Flow

    3.8. Control FlowJava, like any programming language, supports both conditional statements and loops ...

  6. Core Java Volume I — 3.5. Operators

    3.5. OperatorsThe usual arithmetic operators +, -, *, / are used in Java for addition, subtraction, ...

  7. Core Java Volume I — 3.3. Data Types

    3.3. Data TypesJava is a strongly typed language(强类型语音). This means that every variable must have a ...

  8. Core Java Volume I — 5.1. Classes, Superclasses, and Subclasses

    5.1. Classes, Superclasses, and SubclassesLet's return to the Employee class that we discussed in th ...

  9. Core Java Volume I — 4.6. Object Construction

    4.6. Object ConstructionYou have seen how to write simple constructors that define the initial state ...

随机推荐

  1. luoguP5068 [Ynoi2015]我回来了

    https://www.luogu.org/problemnew/show/P5068 ynoi 中的良心题啊 考虑用 bitset 来维护里一个点距离小于 $ y_i $ 的点,那么答案就是一堆 b ...

  2. 面向对象之-@classmethod、@staticmethod和@classonlymethod的区别

    实例方法.静态方法与类方法的含义 实例方法(普通方法)的含义就是需要类对象实例之后才能调用的方法,该方法的基本格式为: def test(self,*args,**kwargs): # 第一个参数必须 ...

  3. Spring Boot启动过程(三)

    我已经很精简了,两篇(Spring Boot启动过程(一).pring Boot启动过程(二))依然没写完,接着来. refreshContext之后的方法是afterRefresh,这名字起的真.. ...

  4. jdk(1.8)命令行工具(二)

    2.3 jinfo:java配置信息工具 jinfo(Configuration Info for Java)的作用是实时的查看和调整虚拟机的各项参数.使用jps -v 可以查看虚拟机启动时显示指定的 ...

  5. npm安装包很慢

    每次安装时: 可以通过指定 --registry,指向国内镜像服务器地址来加快安装速度. npm install -gd express --registry=http://registry.npm. ...

  6. Spring注解学习笔记一

    一.Retention注解Retention(保留)注解说明,这种类型的注解会被保留到那个阶段. 有三个值: 1.RetentionPolicy.SOURCE —— 这种类型的Annotations只 ...

  7. PlistBuddy简单使用

    PlistBuddy简单使用 由于PlistBuddy并不在Mac默认的Path里,所以我们得通过绝对路径来引用这个工具: 查看帮助 /usr/libexec/PlistBuddy --help 下面 ...

  8. ownCloud问题处理server replied 423 Locked to

    打开owncloud 数据库备份:oc_file_locks表(备份免错哦)然后清空该表,客户端同步一次,故障解决 owncloud大的数据无法同步..

  9. F6&F7adjust the volume

    Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard La ...

  10. (转)DB2高可用性灾难恢复

    DB2 HADR概述 原文:https://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0508luojunkai/