Java内存Happen-Before
- 在Thread.start之前的操作,hb 线程里面的操作
- 对一个锁的解锁,hb 重新获得锁
- 一个线程里的所有操作,hb其他线程调用这个线程的join返回后。
- 对一个volatile的写入操作,hb读取操作
- 对一个并发集合(CopyOnWriteList等)的写入操作,hb于对他的删除、读取操作
hb的含义,是之前的操作写入的东西,对之后的操作都是可见的
具有传递性,如果A hb B,B hb C,那么A hb C
- Each action in a thread happens-before every action in that thread that comes later in the program's order.
- 在同一个线程里面,前面的操作总是 hb 后面的操作
- An unlock (
synchronized
block or method exit) of a monitor happens-before every subsequent lock (synchronized
block or method entry) of that same monitor. And because the happens-before relation is transitive, all actions of a thread prior to unlocking happen-before all actions subsequent to any thread locking that monitor. - 对于同一个锁,释放锁之前的操作,总是 hb 之后获取锁的操作。因此,之前获取锁的线程,总是hb之后获取锁的线程。
- A write to a
volatile
field happens-before every subsequent read of that same field. Writes and reads ofvolatile
fields have similar memory consistency effects as entering and exiting monitors, but do not entail mutual exclusion locking. - 对Volatile的写操作,总是hb读操作。对volatile的读写在进入和退出锁上有相似的的内存一致性,但不是互斥锁。
- A call to
start
on a thread happens-before any action in the started thread. - 在Thread.start之前发生的,总是hb 线程里面执行的
- All actions in a thread happen-before any other thread successfully returns from a
join
on that thread. - 在线程里面发生的,总是hb 线程Join返回之后发生的
The methods of all classes in java.util.concurrent
and its subpackages extend these guarantees to higher-level synchronization. In particular:
- Actions in a thread prior to placing an object into any concurrent collection happen-before actions subsequent to the access or removal of that element from the collection in another thread.
- 在同步集合中之前放入对象总是hb之后的读取和删除
- Actions in a thread prior to the submission of a
Runnable
to anExecutor
happen-before its execution begins. Similarly forCallables
submitted to anExecutorService
. - 在Executor执行之前发生的,总是hb提交的Runnable的代码
- Actions taken by the asynchronous computation represented by a
Future
happen-before actions subsequent to the retrieval of the result viaFuture.get()
in another thread. - 在Future里面执行的,总是hb Future.get之后发生的
- Actions prior to "releasing" synchronizer methods such as
Lock.unlock
,Semaphore.release
, andCountDownLatch.countDown
happen-before actions subsequent to a successful "acquiring" method such asLock.lock
,Semaphore.acquire
,Condition.await
, andCountDownLatch.await
on the same synchronizer object in another thread. - 在锁释放前发生的(如
Lock.unlock
,Semaphore.release
, andCountDownLatch.countDown)总是hb 之后成功获取锁后发生的。
- For each pair of threads that successfully exchange objects via an
Exchanger
, actions prior to theexchange()
in each thread happen-before those subsequent to the correspondingexchange()
in another thread. - 在两个通过Exchanger进行交换的线程,在调用exchange之前发生的,总是hb另外一个线程响应exchange
- Actions prior to calling
CyclicBarrier.await
andPhaser.awaitAdvance
(as well as its variants) happen-before actions performed by the barrier action, and actions performed by the barrier action happen-before actions subsequent to a successful return from the correspondingawait
in other threads. - 在调用
CyclicBarrier.await
andPhaser.awaitAdvance之前发生的,总是hb 被内存栅栏执行的动作,内存栅栏执行的动作,总是hb 其他线程调用await返回之后
转载于:https://www.cnblogs.com/bobdeng/p/8960783.html
Java内存Happen-Before相关推荐
- JSR 133 Java内存模型以及并发编程的最权威论文汇总
Java内存模型 先看官方文档: https://docs.oracle.com/javase/specs/ JSR 133:Java TM内存模型和线程规范修订版:https://www.jcp.o ...
- 转:【Java并发编程】之十六:深入Java内存模型——happen-before规则及其对DCL的分析(含代码)...
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17348313 happen-before规则介绍 Java语言中有一个"先行发生 ...
- 聊聊高并发(三十六)Java内存模型那些事(四)理解Happens-before规则
在前几篇将Java内存模型的那些事基本上把这个域底层的概念都解释清楚了,聊聊高并发(三十五)Java内存模型那些事(三)理解内存屏障 这篇分析了在X86平台下,volatile,synchronize ...
- Java内存模型常见问题
1.什么是内存模型? 在多核系统中,处理器一般有一层或者多层的缓存,这些的缓存通过加速数据访问(因为数据距离处理器更近)和降低共享内存在总线上的通讯(因为本地缓存能够满足许多内存操作)来提高CPU性能 ...
- 《深入理解JVM.2nd》笔记(二):Java内存区域与内存溢出异常
文章目录 概述 运行时数据区域 程序计数器 Java虚拟机栈 本地方法栈 Java堆 方法区 运行时常量池 直接内存 HotSpot虚拟机对象探秘 对象的创建 第一步 第二步 第三步 第四步 最后一脚 ...
- 【Java并发编程】之十六:深入Java内存模型——happen-before规则及其对DCL的分析(含代码)...
Java并发编程系列 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/mmc_maodun/article/details/17348313 转载请注 ...
- 从底层吃透java内存模型(JMM)、volatile、CAS
前言 随着计算机的飞速发展,cpu从单核到四核,八核.在2020年中国网民数预计将达到11亿人.这些数据都意味着,作为一名java程序员,必须要掌握多线程开发,谈及多线程,绕不开的是对JMM(Java ...
- Java内存溢出详解之Tomcat配置
Java内存溢出详解 转自:http://elf8848.iteye.com/blog/378805 一.常见的Java内存溢出有以下三种: 1. java.lang.OutOfMemoryError ...
- 32位jdk最大内存_你了解Java 内存区域和GC机制吗?
目录 Java垃圾回收概况 Java内存区域 Java对象的访问方式 Java内存分配机制 Java GC机制 垃圾收集器 Java垃圾回收概况 Java GC(Garbage Collection, ...
- 循序渐进:带你理解什么是Java内存模型
近期笔者在阅读<深入理解Java虚拟机:JVM高级特性与最佳实现(第3版)>,书中提到关于Java内存模型的知识点,但是看完之后还是感觉有些模糊,便查阅一些其他相关资料.本文是笔者经过对知 ...
最新文章
- 深度学习以及卷积基础
- vivo U1正式亮相
- linux怎么增加cpu负载,Linux下的CPU平均负载
- Silverlight C# 游戏开发:Flyer09扇动翅膀的蝴蝶
- PL/SQL Developer结合oracle精简客户端配置说明
- jackson 序列化_jackson序列化与反序列化的应用实践
- Visual Studio 2019 首个预览版本抢先看,有啥新功能?
- parameterType 属性、typeAliases 别名
- 64如何传入后台_如何保证API接口数据安全?
- inline-block从入门到精通
- w ndows模拟器,iPad 模拟器 模拟器(windows - iPadian)
- 【有利可图网】PS教程:制作变形文字
- JS实现对联浮动广告(初级)
- SOC2- 安全性、可用性、进程完整性、机密性和隐私性五大控制属性
- 51单片机LED数码管
- Radis缓存异常以及处理方案(雪崩击穿穿透预热降级)
- 信息时代碎片化学习的理解
- Java内容整理回顾——第一回 小卷入坑记
- JS实现页面检索(搜索)功能,类似浏览器搜索
- 解密区块链:当你最需要信任的时候,它会为你建立信任
热门文章
- CISCO路由器交换机简介及Packet+Tracer使用说明
- 免费stm32视频教程分享:心率检测仪的设计与实现
- Java云同桌学习系列(二十二)——mongoDB数据库
- python average函数怎么用,Python Numpy MaskedArray.average()用法及代码示例
- 基于php+mysql的网上购物商城系统
- linux杀死ltp进程,LTP套件使用方法详解
- 云从科技上市在即,或成为小一号的商汤科技?
- Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律
- python批量注释快捷键wingide_WingIDE 常用快捷键
- 在电脑上如何录制游戏