Java – there can be more than 32 locks in the concurrenthashmap

I read that concurrent HashMap is better than hashtable in terms of multithreading, because it maps wide locking at the bucket level instead of mapping Each map can be locked up to 32 times Want to know why 32 and why not more than 32 locks

Solution

If you are talking about Java Concurrent HashMap, limit it to binary:

If you read the source code, it is obvious that the maximum number of segments is 2 ^ 16, which should be sufficient for any possible demand in the near future

You may have been considering some alternative experimental implementations, such as this one:

Note that when more than 32 threads attempt to update a single concurrenthashmap, factors other than synchronization efficiency are usually bottlenecks

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>