Several threads are accessing a ConcurrentHashMap
, which is populated with entries when the application loads up, and is rarely modified structurally thereafter. Most operations on the map are either reading, or replacing existing entry values. Very rarely new entries are created or removed, and even then just a few every time.
Therefore, usually contention is predicted on the entry level only.
What should I set the concurrencyLevel
to? I was thinking of value of 1
, because the map is hardly ever modified structurally, and when that happens, I rather pay the price of contention over larger internal strucute size.
EDIT: The suggested link answers my question, but it's worth mentioning that although concurrencyLevel
of 1 is sufficient in my case, ConcurrentHashMap
still allows for concurrent read/write access on the Entry level without locking, since it features a volatile
read/write semantics.