On Aug 22, 2008, at 16:29, Jeremias Maerki wrote:

[Peter: ]
What happens is SEGMENT_COUNT is not a power of 2? Or, what obliges
SEGMENT_COUNT to be a power of 2?

There's a lot of AND-ing of hash codes to determine the segments and
buckets and that's much easier to handle if you have a power of 2 and
can shift bits around.

Confirmed. SEGMENT_COUNT is actually a somewhat arbitrary number. Dividing the map into 32 segments allows for concurrent (and synchronized!) access by 32 threads at the same time, without involving waits (provided that each thread accesses a different segment of the map). This is the most significant benefit compared to synchronizedMap(), which synchronizes the whole put() method, so each thread calling put() blocks all others.



Reply via email to