有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

爪哇番石榴在初始容量和并发水平上的差异

番石榴说

https://guava.dev/releases/16.0/api/docs/com/google/common/cache/CacheBuilder.html#initialCapacity(int)

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有什么意义呢?这是不是文档输入错误


共 (1) 个答案

  1. # 1 楼答案

    在后台,Guava的缓存被实现为多个哈希表,每个哈希表都有一个专用锁,因此并发写入不会在单个锁上竞争

    initialCapacity指的是整个缓存的容量,而不是每个底层表的容量。8个表,每个表的大小为8,最多可以处理64个元素,因此文档是正确的