java - ConcurrentHashMap的线程内存管理

标签 java multithreading

我的疑问是 HashTable get() 方法是同步读取的。但是 ConcurrentHashMap 已经消除了这个限制。但是,只有同步块(synchronized block)才能访问内存中的最新值。如果是这种情况,如果其他线程已更新它,然后在本地缓存该值,它将访问最新值。这是怎么做到的。 此外,可重入锁还像同步块(synchronized block)一样从内存中获取和更新最新值。 谢谢

最佳答案

ConcurrentHashMap 的 javadoc这一点很清楚:

Retrievals reflect the results of the most recently completed update operations holding upon their onset. (More formally, an update operation for a given key bears a happens-before relation with any (non-null) retrieval for that key reporting the updated value.)

“happens-before”文本特指 java memory consistency 的行为.

关于java - ConcurrentHashMap的线程内存管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28137476/

相关文章:

c# - 使类字段线程安全

Android Looper 和调用栈

java - 有没有办法计算对原始变量的访问线程数?

multithreading - Bash有线程产量吗?

java - @ImportResource 不工作

列表中列表的Java 8 Stream过滤值

java - 创建名称为authenticationTokenFilterBean 的bean 时出错 : Unsatisfied dependency expressed through field tokenUtils

java - Spigot/Bukkit - 播放自己的声音/音乐 - Java

javascript - Thymeleaf 将数据从 html id 传递到 thymeleaf 变量

python - threading.timer 在 python 中如何工作