ConcurrentHashMap为什么不用segment
时间: 2023-10-14 12:05:13 浏览: 83
java中ConcurrentHashMap的读操作为什么不需要加锁
5星 · 资源好评率100%
ConcurrentHashMap在JDK1.8版本中不再使用Segment,而是采用了一种新的实现方式,即将数据分散存储在多个节点上,每个节点上都有自己的锁。这样做的好处是,在多线程环境下,每个线程可以独立访问不同的节点,从而提高并发性能。而使用Segment的方式则需要对整个ConcurrentHashMap进行加锁,导致并发性能的下降。所以,在JDK1.8版本中,ConcurrentHashMap不再使用Segment,而是通过细粒度的锁来保证线程安全性。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [阿里面试题:ConcurrentHashMap为什么是线程安全的?](https://download.csdn.net/download/weixin_38717171/14854002)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [ConcurrentHashMap(JDK1.8)为什么要放弃Segment](https://blog.csdn.net/mian_CSDN/article/details/70185104)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [【Java并发】- ConcurrentHashMap原理解析(Segment版本)(转)](https://blog.csdn.net/LightOfMiracle/article/details/73235252)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文