简体   繁体   English

在Java中的ConcurrentHashMap中重新散列会增加段的数量吗?

[英]Does rehashing in ConcurrentHashMap in Java increase the number of segments ?

does rehashing increase the number of segments ? 重组是否会增加细分数量? or does concurrency level change at the time of rehashing CHM ? 或者在重组CHM时并发级别是否会发生变化?

If not (most probably) , then why is this behaviour given in java, as the number of entries increases in CHM, more threads will be accessing the same segment and may require the higher level of concurrency ? 如果不是(最有可能),那么为什么在java中给出了这种行为,因为CHM中的条目数量增加,更多的线程将访问同一个段并且可能需要更高级别的并发性?

EDIT: I guess if the functionality of increase in segments were given, lock on all segments would be required. 编辑:我想如果给出了段增加的功能,则需要锁定所有段。 is that the reason ? 那是什么原因?

The number of segments don't change as the ConcurrentHashMap grows in size. 当ConcurrentHashMap的大小增加时,段的数量不会改变。 The number of thread which could access a collection are not as important as the number the number of active threads accessing the map. 可以访问集合的线程数量不如访问映射的活动线程数量那么重要。 If you have 4 cores this is at most 4, even if all they do is access the map and do nothing else. 如果你有4个核心,这最多只有4个核心,即使他们只是访问地图而不做任何其他事情。 This is an extreme example. 这是一个极端的例子。

In reality, you tend to have less than one thread accessing a map at once and sometimes 2-4 threads accessing a map which is when using segments helps. 实际上,您往往只有一个线程一次访问一个地图,有时2-4个线程访问地图,这在使用分段时有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM