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

Kwok, Grace (MSCIBARRA) Grace.Kwok at mscibarra.com
Tue Nov 20 18:38:54 EST 2007


Posting again due to posting problem earlier.
========================= 

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();
}
 
 
If I were to base soft hash map on  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.



More information about the Concurrency-interest mailing list