Java synchronized 保证可见性
Java juc 锁 大约 743 字原因
synchronized
在代码块执行结束后会将执行结果刷新到主存中。
所以synchronized
也和volatile
有可见性的作用。
JMM 规范
synchronized
在可见性上和volatile
作用一致。
Doug Lea
原文节选:
In terms of atomicity, visibility, and ordering, declaring a field as volatile is nearly identical in effect to using a little fully synchronized class protecting only that field via get/set methods, as in: Declaring a field as volatile differs only in that no locking is involved. In particular, composite read/write operations such as the "++'' operation on volatile variables are not performed atomically.
final class VFloat {
private float value;
final synchronized void set(float f) { value = f; }
final synchronized float get() { return value; }
}
引用段落出处
阅读 1286 · 发布于 2021-09-03
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Spring Boot 代码中生成 MultipartFile 对象阅读 264
-
Android 软键盘遮挡控件阅读 1861
-
Git 命令之查看及设置用户名邮箱阅读 3034
-
OpenResty 返回中文乱码问题阅读 5171
-
MongoDB 过期索引(TTL 索引)阅读 3825
-
Linux xxx is not in the sudoers file.This incident will be reported阅读 2345
-
Vue2 生命周期阅读 237
-
SQL 删除重复数据保留最新的一条阅读 1861
-
IDEA 滚轮调节字体大小阅读 2349
-
MySQL 合并字符串函数:CONCAT、CONCAT_WS、GROUP_CONCAT阅读 3846