[concurrency-interest] question about ConcurrentHashMapV8.RemappingFunction

Doug Lea dl at cs.oswego.edu
Tue Jun 26 07:46:32 EDT 2012

> Hi Everyone,
> I tried to search for it (not too hard), but did not succeed, so I would
> post the question here:
> Was there any reason why the ConcurrentHashMapV8.RemappingFunction must
> return not-null when called from
> ConcurrentHashMapV8.compute(K,RemappingFunction) method?

There was some list discussion about this when CHMV8 was first
released. I don't have a strong opinion about it. Some argued
that returning null from remapper is in practice usually an
error so should be trapped, so this is what it now does.
But having null return indicate deletion does seem handy.
If anyone knows a knock-down argument showing that it is
more than handy, and is essential for some use-case, please
feel free to post it.


> I understand that the map does not allow null keys or values.
> However, because of this, the null value returned from the
> RemappingFunction in this case could indicate the need to remove the
> mapping from the map.
> I also understand that this would make the compute() method more complex
> which would possibly reduce performance, on the other hand, it would be
> useful to have a way to carry this out, possibly with yet another compute
> method which behaves similarly to compute but caters for removal upon null
> returned from the RemappingFunction.
> It would allow algorithms which operate on an arbitrarily large amount of
> keys used during the lifetime of the map to clean the map up after
> themselves once the mapping is unused. At the moment such algorithms would
> need to do compute(K, RemappingFunction) with the function returning a
> magic-value, then call remove(K, magic-value), which would lead to double
> hash-lookup and additional cost due to the two mutating operations instead
> of one in the success case for a remove race.
> Thanks and best regards,
> Robert Varga
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

More information about the Concurrency-interest mailing list