Does ConcurrentHashMap overwrite the number of segments in Java?

overwrites the increase in the number of segments? or change in concurrency level during CHM reboot?

If this is not the case (most likely), then why is this behavior indicated in java, as the number of records increases in CHM, more threads will access the same segment and may require a higher level of concurrency?

EDIT: I think if segment expansion functionality was provided, locking would be required for all segments. This is the reason?

+4
source share
1 answer

The number of segments does not change as the size of ConcurrentHashMap increases. The number of threads that could access the collection is not as important as the number of active threads accessing the map. If you have 4 cores, this is not more than 4, even if all they do is access the map and do nothing. This is an extreme example.

In fact, you usually have less than one thread accessing the map immediately, and sometimes 2-4 threads accessing the map that is used when using segments.

0
source

All Articles