今天重扫了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. vue 路由传参

      mode:路由的形式 用的哪种路由 1.hash 路由 会带#号的哈希值 默认是hash路由   2.history路由 不会带#的     单页面开发首屏加载慢怎么解决?单页面开发首屏加载白屏怎 ...

  2. OWASP JUICE SHOP部分题解

    本文作者:S0u1 0×00 简介 OWASP JUICE SHOP是一个开源的web应用靶场,里面包含了共记47个漏洞挑战任务,囊括了OWASP TOP 10的各个点,是一个很不错的渗透测试练手项目 ...

  3. jscover使用说明-总体说明

    1.总体说明 这个文档现在是完善和准确的,不管怎样,尽量去参考JSCoverage documentation. 1.1.介绍 JSCove是一个用来显示JavaScript项目代码覆盖率的工具,它是 ...

  4. asp.net图片上传代码

    前端: <form action="/ImageUpload.ashx" method="post" enctype="multipart/fo ...

  5. 根据域名获取ip地址gethostbyname

    #include <sys/socket.h> #include <stdio.h> #include <netdb.h> int main(int argc, c ...

  6. [Alpha]Scrum Meeting#10

    github 本次会议项目由PM召开,时间为4月13日晚上10点30分 时长25分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写每日例会报告撰写并整理任务分配博客 撰写每日例会报告配合测试.验收 ...

  7. 02-url路由分配及模板渲染方式

    本章主要内容 1.url基本概念及格式 2.path和re_path 3.模板路径配置 4.模板渲染方式 1.url基本概念及格式 URL(uniform Resoure Locator)统一资源定位 ...

  8. [性能测试]:内存泄漏以及MAT(Memory Analyzer Tool)工具使用分析

    一.今天在查看服务器时候,发现内存使用率直接就到99%了, 二.用ps -uaxw查看一下,每个占用内存较多的进程情况: 三,挑出可疑的进程,生成dump文件: jmap -dump:format=b ...

  9. 论文分享NO.1(by_xiaojian)

    论文分享第一期-2019.03.14: 1. Non-local Neural Networks  2018 CVPR的论文 2. Self-Attention Generative Adversar ...

  10. Zynq-7000 FreeRTOS(二)中断:PL中断请求

    总结Zynq-7000的PL发送给PS一个中断请求,为FreeRTOS中断做准备. UG585的P225显示了系统的中断框图,如下图所示. 图:ZYNQ器件的中断框图 UG585的P227画出来中断控 ...