[concurrency-interest] Questions on ConcurrentHashMap

David Holmes dcholmes at optusnet.com.au
Wed Nov 28 23:28:25 EST 2007


Joe,

> Joe Bowbeer wrote:
> Great! I go check the docs to see what the semantics of map.clear()
> actually are in this case.  It doesn't say.  So how does this work?
> Semantics are implementation dependent.  Is the implementation
> fixed for all time or can it change?

The docs are a little brief here :) I think all it can say is that after
clear() returns, every mapping that was present when clear() "commenced",
will have been removed. New mappings concurrent with clear() may or may not
have been removed. But even this is a loose description as "commenced" is
really determined by the locking strategy.

The implementation could certainly change in theory. Eg we might lock all
segments then clear all, rather than locking, clearing, unlocking, one at a
time. In practice it is unlikely to change.

The atomicity (or not) of CHM methods are often subject to debate.

Cheers,
David



More information about the Concurrency-interest mailing list