今天重扫了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. robot framework接口测试之二-四种常见的POST提交数据方式

    写接口测试用例时,遇到以json格式提交数据时,报错,Request如下图: Response如下图: 改成form格式提交,可以正常运行,如下图: 代码如下: ------------------- ...

  2. 在PL/SQL里直接插入日期时提示 is not a valid date and time的解决方法

    在PL/SQL Developer里直接往表里插入日期格式的数据时,经常会出现" is not a valid date and time"的错误,这是因为Oracle的日期格式和 ...

  3. SAE实践——创建新应用开启MySQL服务

    1. 创建SAE应用 当创建完成SAE账户之后,即可创建SAE应用.点击创建新应用按钮,创建一个新的SAE 应用 阅读提示信息,等待五秒,点继续创建. 填写应用信息完成创建.可选择PHP5.3和空应用 ...

  4. 在eclipse中,用maven创建web项目

    备注:该文档是之前学习时,根据网上其他童鞋的经验自己测试后梳理,如有侵权,请勿怪,感谢! 1.在eclipse中用maven创建项目,右键new>>Maven Project 2.点击ne ...

  5. 架构师养成记--18.NIO

    有人叫new IO 我这里就叫Non-block IO 经典概念: Buffer(缓冲区):之前直接通过流,现在提供一个buffer存放数据. Channel:管道,包括ServerSocketCha ...

  6. ES6之新增set数据结构

    学习set set是ES6中的新增的数据结构,是一种构造函数,类似于数组,但是里面的元素都是唯一的,不重复的. 例如: const set = new Set(); [1,2,3,4,5,2,1,2, ...

  7. 自定义ASP.NET Core日志中间件

    这个日志框架使用的是ASP.NET Core的NLog,用来记录每次请求信息和返回信息. 1.首先创建一个Web应用项目,我选择的是MVC模板: 2.使用NuGet添加Microsoft.Extens ...

  8. Go语言string包详解

    strings包实现了用于操作字符的简单函数. 查找操作 判断给定字符串s中是否包含子串substr, 找到返回true, 找不到返回false func Contains(s, substr str ...

  9. Scrapyd-Client的安装

    1. pip安装 这里推荐使用pip安装,相关命令如下: pip3 install scrapyd-client 2.验证安装 安装成功后会有一个可用命令,叫作scrapyd-deploy,即部署命令 ...

  10. 微信 oauth 登录 ,回调两次,一个坑,记录一下。

    在做微信某个功能的时候,大致需求是:静默授权,得到openId ,然后拿着openId调用接口,判断是否关注.如果是关注的,则发放礼券.每个我网站的会员只会发放一次礼券.如果第二次则会提示已领取过礼券 ...