[concurrency-interest] ConcurrentHashMapV8

Ben Manes ben_manes at yahoo.com
Sun Aug 28 17:05:39 EDT 2011


reply-all:



________________________________
From: Ben Manes <ben_manes at yahoo.com>
To: dl at cs.oswego.edu
Sent: Sunday, August 28, 2011 2:00 PM
Subject: Re: [concurrency-interest] ConcurrentHashMapV8

If computation is being added, then bulk computation should be implemented as well. This is useful when a computation requires an I/O call, so a batch operation is an important optimization. The simplest approach is to insert placeholder nodes that are populated after the computation has completed. (e.g. see this old decorator that supplied it: http://code.google.com/p/concurrentlinkedhashmap/wiki/SelfPopulatingCache)

It wasn't obvious to me how recursive computations are handled for the same key and appears to livelock. This is an error condition that used to deadlocked MapMaker. I fixed this by failing fast if Thread.holdsLock() was true prior to waiting for the computation to finish.

The exceptional computation case may be worth documenting. CHM only fails the computing thread and allows the waiting threads to retry the computation. In other implementations the waiting threads rethrow the exception and don't recompute.

A recompute (a.k.a. refresh) method may also be useful, though can be adequately supplied by usages. This recomputes the value, but allows readers to continue to use the stale value until it completes. This can be useful for cache invalidation where it is preferred vs. exposing the latency to the user (if naively done by removing first).

-Ben

On Sun Aug 28th, 2011 12:24 PM PDT Doug Lea wrote:

>
>A candidate replacement for java.util.concurrent.ConcurrentHashMap
>is now available as jsr166e.ConcurrentHashMapV8. This version
>is much more amenable to upcoming support for aggregate
>parallel operations (including, already, method "computeIfAbsent'
>using a stand-in MappingFunction type).
>
>The internal design is interestingly different.
>Read the internal documentation for details.
>(http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/ConcurrentHashMapV8.java?view=log)
>
>Please give it a try, and let us know about experiences.
>
>Links:
>    *  API specs:  http://gee.cs.oswego.edu/dl/jsr166/dist/jsr166edocs/
>    * jar file: http://gee.cs.oswego.edu/dl/jsr166/dist/jsr166e.jar (compiled using Java7 javac).
>    * Browsable CVS sources: http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/
>
>
>_______________________________________________
>Concurrency-interest mailing list
>Concurrency-interest at cs.oswego.edu
>http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110828/ca3309f3/attachment.html>


More information about the Concurrency-interest mailing list