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.