[concurrency-interest] Question: Concurrent Memoizer pattern withSoftHashMap

Tim Peierls tim at peierls.net
Tue Nov 20 20:01:51 EST 2007


On Nov 20, 2007 7:04 PM, David Holmes <dcholmes at optusnet.com.au> wrote:

> Is there a reason you can't simply wrap the Future in a SoftReference
> directly so that your ConcurrentHashMap cache is mapping from K ->
> SoftReference<Future<V>> ? If you find a value with a null referent then
> you
> can remove the WeakReference from the map and replace with a new one. You
> might need additional expunging logic if your cache might accumulate
> "empty"
> SoftReferences.
>

I found this surprisingly hard to get right. I have code that I would have
to figure how to release that lets you build Memoizers using plain, soft, or
weak references. The plain version is just standard Memoizer.

But closer at hand is the Google Collections library and ReferenceCache from
the Guice codebase. Somewhere in there you can find what you need.

--tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20071120/a8b5988c/attachment.html 


More information about the Concurrency-interest mailing list