问题描述
根据Java Concurrency in Practice,第11.4.3章说:
According to Java Concurrency in Practice, chapter 11.4.3 says:
我仍然有问题来理解和可视化锁条带和桶机制。
有人可以用很好的理解词解释这一点:)
I still have problems to understand and visualize the lock striping and buckets mechanism.Can someone explain this with good understanding words :)
提前感谢。
推荐答案
哈希映射建立在数组上,其中哈希函数将对象映射到底层数组中的元素。让我们说底层数组有1024个元素 - ConcurrentHashMap实际上将它转换为16个不同的64个元素的子数组,例如。 {0,63},{64,127}等。每个子数组都有自己的锁,因此修改{0,63}子数组不会影响{64,127}子数组 - 可以写入第一个子数组,而另一个线程写入第二个子数组。
The hash map is built on an array, where the hash function maps an object to an element in the underlying array. Let's say the underlying array has 1024 elements - ConcurrentHashMap actually turns this into 16 different sub-arrays of 64 elements, e.g. {0, 63}, {64, 127}, etc. Each sub-array has its own lock, so modifying the {0, 63} sub-array doesn't impact the {64, 127} sub-array - one thread can write to the first sub-array while another thread writes to the second sub-array.
这篇关于需要简单的解释如何“锁定条纹”使用ConcurrentHashMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!