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

Kwok, Grace (MSCIBARRA) Grace.Kwok at mscibarra.com
Wed Jan 9 16:54:42 EST 2008


>>>>> You could build a Memoizer from that [google's referenceMap].
 
If I have a referenceMap with Strong key and Soft value combining with
the memoizer pattern, the soft reference will be on the FutureTask. We
would never have any hard reference to a FutureTask despite the fact
that there might be additional hard reference to the value inside the
FutureTask as it is returned. That means even if there is additional
hard reference to the value inside the FutureTask as value is returned,
the FutureTask itself (along with the value) inside the map is subject
to garbage collection. That would not be what I want. Does anyone have
suggestions of ways around it?

Thanks, Grace

> 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();

> }



________________________________

From: tpeierls at gmail.com [mailto:tpeierls at gmail.com] On Behalf Of Tim
Peierls
Sent: Wednesday, November 21, 2007 11:31 AM
To: Kwok, Grace (MSCIBARRA)
Cc: Charles Fry; concurrency-interest at cs.oswego.edu
Subject: Re: [concurrency-interest] Question: Concurrent Memoizer
pattern with SoftHashMap


Grace.Kwok at mscibarra.com> wrote: 


	Thanks all for the feedbacks. 
	
	1) I went to the GUICE javadoc but do not see a ReferenceCache
class 
	there. 
	http://google-guice.googlecode.com/svn/trunk/javadoc/index.html 


ReferenceCache and AbstractReferenceCache are internal classes to Guice,
but the source is available and only lightly coupled to the rest of
Guice. The maintainers said they intend to release these classes
separately, but I don't think it has happened yet. 




	
<http://google-guice.googlecode.com/svn/trunk/javadoc/index.html> I do
see a ReferenceMap class in the collections package.


You could build a Memoizer from that. 

  


	2) Are the the google collections and guice library both in
Alpha version? 
	


No, only one of them is alpha, Google Collections (0.5). Guice is 1.0. 

--tim
--------------------------------------------------------

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080109/5444cd02/attachment.html 


More information about the Concurrency-interest mailing list