我了解在HashMap中,条目(Key,Value)是根据hash(Key.hashCode)放在桶中的-->表示桶位置的索引.如果条目已经放置在该位置,则会创建一个链表,并且新条目(如果它具有不同的键 --> 通过 equals() 方法)放置在链表的开头.
I understand that in HashMap, the entries (Key, Value) are placed in buckets based on hash(Key.hashCode)--> The index that denotes the bucket location. In case an entry is already placed at that location, there is a linked list created and the new entry (if it has different key --> via equals() method) is placed at the beginning of the linked list.
桶是地图数组中的一个单独的槽.这对于 HashMap
和 ConcurrentHashMap
都是一样的.从概念上讲,后者将其数组分解为段(每个段都是引用数组),仅此而已.请注意,Java 8 中的 CHM 不再有段,而是一个数组.
A bucket is an individual slot in the map's array. This is the same with both HashMap
and ConcurrentHashMap
. Conceptually, the latter has its array broken into segments (each segment is an array of references), but that's it. Note that the CHM in Java 8 no longer has segments, it's all a single array.
是的,这就是称为分段锁定的方案.它减少了线程间争用,但并没有消除它.
Yes, it's the scheme known as segmented locking. It reduces inter-thread contention, but does not eliminate it.
这篇关于ConcurrentHashMap的Segment和HashMap的bucket在理论上有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!