Reputation: 6854
Guava docs says
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.
So what's the point of using initialCapacity
if it's going to create 8 tables with 8 rows ? Is this some documentation typo?
Upvotes: 0
Views: 2971
Reputation: 9023
Under the hood, Guava's cache is implemented as multiple hash tables, each with a dedicated lock, so that concurrent writes don't all contest on a single lock.
initialCapacity
refers to the capacity of the entire cache, not each individual underlying table. 8 tables each of size 8 can together handle up to 64 elements, so the documentation is correct.
Upvotes: 1