[concurrency-interest] Question: Concurrent Memoizer pattern with SoftHashMap

Charles Fry fry at google.com
Tue Nov 20 20:27:27 EST 2007


Have you looked at ReferenceCache?

Charles

On Nov 20, 2007 6:19 PM, Kwok, Grace (MSCIBARRA)
<Grace.Kwok at mscibarra.com> wrote:
>
>
>
> Hi all,
>
>     I am refactoring code and would like to use the Memoizer pattern  but I
> need my cache to be a concurrent soft hash map instead of simply a
> ConcurrentHashMap.
>
> // recall the concurrent Memoizer pattern where cache is a
> ConcurrentHashMap.
> public V compute(final A arg) throws Exception{
>    Future<V> f = cache.get(arg);
>    if(f==null){
>       Callable<V> eval = new Callable<V>(){....}
>
>     FutureTask<V> ft = new FutureTask<V>(eval);
>     f = cache.putIfAbsent(arg, ft);
>     if(f == null){
>         f = ft;
>         ft.run();
>     }
> }
> f.get();
> }
>
>
>
> We are basing our soft hash map from this:
> http://www.javaspecialists.co.za/archive/Issue098.html
> (search for title "New SoftHashMap")
>
> Does anyone has any suggestion of having the Memoizer and SoftHashMap
> concepts working together such that I do not need to use explicit
> synchronization?
>
> Thanks, Grace
>
>
>
>
>
>  ________________________________
>
>
> NOTICE: If received in error, please destroy and notify sender. Sender does
> not intend to waive confidentiality or privilege. Use of this email is
> prohibited when received in error.
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>


More information about the Concurrency-interest mailing list