简体   繁体   中英

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 ?

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 ?

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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