Guava 文档说
Sets the minimum total size for the internal hash tables. For example, if the initial capacity is 60, and the concurrency level is 8, then eight segments are created, each having a hash table of size eight. Providing a large enough estimate at construction time avoids the need for expensive resizing operations later, but setting this value unnecessarily high wastes memory.
如果要创建 8 个 8 行的表,那么使用 initialCapacity
有什么意义呢?这是一些文档错字吗?
最佳答案
在底层,Guava 的缓存被实现为多个哈希表,每个哈希表都有一个专用锁,因此并发写入不会全部竞争单个锁。
initialCapacity
指的是整个缓存的容量,而不是每个单独的基础表的容量。 8 个表,每个表的大小为 8,最多可以处理 64 个元素,因此文档是正确的。
关于java - Guava - intialCapacity 和 concurrencyLevel 的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58956594/