Reputation: 5664
As entries increase in the ConcurrentHashMap, rehashing will be done and new hash buckets will be formed (16 to 32). Q: Will the locks(initially 16) will also increase(to 32) or 16 locks will look on 32 hashbuckets(1 lock per 2 hash buckets) and so on as the entries keeps increasing ( just for reference we can take loadfactor as 1)
Onre more question: I want to read the implementaion of ConcurretnHashMap, please share the link(other than Java Docs/code)
Upvotes: 1
Views: 610
Reputation: 24503
The concurrency of a ConcurrentHashMap
is set at initialization and doesn't change. If you use the default of 16, it's always going to be 16, no matter how much the hash gets resized.
A couple things to keep in mind:
ConcurrentHashMap
is more expensive to resize than a normal HashMap
. You should really try to provide it a guess as to the number of entries so that it won't have to resize.
The concurrency is the number of threads that could be writing to the map at the same time in an ideal case. Readers don't lock the hash, so you don't need to count them when you're worrying about concurrency.
Upvotes: 1