我的疑问是 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/