ConcurrentHashMap segment
时间: 2023-10-17 17:26:30 浏览: 99
ConcurrentHashMap的内部结构是由多个Segment组成的。每个Segment都是一个独立的哈希表,拥有自己的锁。Segment内部采用数组来存储键值对,每个数组元素都是一个链表的头节点。通过将整个ConcurrentHashMap分成多个Segment,可以将并发控制的粒度降低到Segment级别,从而提高并发性能。每个操作只需要获取对应Segment的锁,而不需要对整个ConcurrentHashMap进行加锁。这样,在进行写操作时,只需要锁住对应的Segment,而其他Segment的读操作和写操作可以并发进行。这种设计可以充分利用多核处理器的并发能力,提高性能和并发性。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *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: 50%"]
- *2* [黑马-ConcurrentHashMap](https://blog.csdn.net/qq_36811160/article/details/122502972)[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: 50%"]
[ .reference_list ]
阅读全文