Core.Java.Volume.I.Fundamentals.10th.Edition 14.5.8 Volatile域 中文版 章节勘误
今天重扫了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域 中文版 章节勘误的更多相关文章
- 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 ...
- Core Java Volume I — 4.7. Packages
4.7. PackagesJava allows you to group classes in a collection called a package. Packages are conveni ...
- 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 ...
- 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 ...
- Core Java Volume I — 3.8. Control Flow
3.8. Control FlowJava, like any programming language, supports both conditional statements and loops ...
- Core Java Volume I — 3.5. Operators
3.5. OperatorsThe usual arithmetic operators +, -, *, / are used in Java for addition, subtraction, ...
- 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 ...
- 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 ...
- Core Java Volume I — 4.6. Object Construction
4.6. Object ConstructionYou have seen how to write simple constructors that define the initial state ...
随机推荐
- SQL注入不简单?那是你没有懂它的原理~
我们真的了解SQL注入吗? 不管用什么语言编写的Web应用,它们都用一个共同点,具有交互性并且多数是数据库驱动.在网络中,数据库驱动的Web应用随处可见,由此而存在的SQL注入是影响企业运营且最具破坏 ...
- VMware Workstation 14 pro License Keys
AC5XK-0ZD4H-088HP-9NQZV-ZG2R4 CG54H-D8D0H-H8DHY-C6X7X-N2KG6 ZC3WK-AFXEK-488JP-A7MQX-XL8YF ZC5XK-A6E0 ...
- 基于openresty配置https访问
安装方法:http://openresty.org/cn/linux-packages.html 1. openssl的版本信息 [root@localhost conf]# openssl vers ...
- P5242 [USACO19FEB]Cow Dating
题目链接 题意分析 首先我们可以得出计算公式 \[s_i=\prod_{k=1}^i(1-p_k)\] \[f_i=\sum_{k=1}^i\frac{p_k}{1-p_k}\] 那么 \[ans(i ...
- POJ 2234
#include<iostream> #include<stdio.h> #include<algorithm> #define MAXN 100 using na ...
- 安装配置python、beautifulsoup4、pip的心酸总结
1.python下载安装不纠结,但如果要加入到eclipse里面就要注意一下版本,版本不匹配会造成,要不python降级,要不eclipse升级的情况 2.在稍新版本的python立面就附带下载在了p ...
- 集合之五:Set接口(答案)
package com.shsxt.homework; import java.util.ArrayList; import java.util.Collection; import java.uti ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...
- 贪心--cf、education62-C
cf-Education 62-C 题目 C. Playlist time limit per test 2 seconds memory limit per test 256 megabytes i ...
- Homebrew下安装的软件自启动服务管理工具:Launchrocket
帮助管理Homebrew安装的服务的软件,比如使用Homebrew安装的Mysql.Redis.MongoDB,传统方式需要使用命令行的命令,而使用LaunchRocket则可以在图形界面中进行管理. ...