What is the difference between Segment of ConcurrentHashMap and buckets of HashMap theoretically?

后端 未结 1 773
夕颜
夕颜 2021-01-01 02:25

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 a

相关标签:
1条回答
  • 2021-01-01 03:01
    1. 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.

    2. Yes, it's the scheme known as segmented locking. It reduces inter-thread contention, but does not eliminate it.

    0 讨论(0)
提交回复
热议问题