如果并发级别高于 Buckets 数量,ConcurrenthashMap 如何管理?

How ConcurrenthashMap manages if Concurrency level is HIGHER than the number of Buckets?

ConcurrentHashMap使用段级锁定机制来支持并发修改。它具有三个基本参数

在默认情况下,我们有每个桶单锁。如果桶的数量为 32,那么我们将有 每两个桶一个锁

如果桶数少于 并发级别,即如果

,如何管理
Map cMap = new ConcurrentHashMap(16,1,32); 

通常,一个桶使用一个集合(链接列表)来处理在同一个桶中哈希码冲突的项目。在上述情况下,每个桶是否有两个锁,如果是,那么它是如何管理的,(桶中一半的集合使用一个锁,另一半使用第二个锁?)

如果将 ConcurrentHashMap 的大小调整为比锁的数量更多的存储桶,我已经搜索并能够看到答案,但如果情况相反,我无法得到答案,即:

如果并发级别高于 Bucket 数量,ConcurrenthashMap 如何管理?

构造函数中的

This code 应该回答你的问题:

if (initialCapacity < concurrencyLevel)   // Use at least as many bins
    initialCapacity = concurrencyLevel;   // as estimated threads

另见 documentation:

concurrencyLevel the estimated number of concurrently updating threads. The implementation may use this value as a sizing hint.