简体   繁体   中英

Is it possible to have number of locks greater than number of buckets in ConcurrentHashMap in Java?

As we know, java's ConcurrentHashMap has a number of internal locks, and each of them guards some region of the bucket's array.

public ConcurrentHashMap(int initialCapacity, loat loadFactor, int concurrencyLevel)

initialCapacity: 16; loadFactory: 0.75f; concurrencyLevel: 16.

ie Default concurrencyLevel and initialCapacity is same.

Is is possible to have more no. of locks than no. of buckets ?

不,CHM使用每个存储桶作为锁(在Java 7之前,每个存储桶都是ReentrantLock现在每个存储桶都将synchronized 。因此,根据定义,不能有更多的锁。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM