Hi,
Just my 2cents...what you have below is probably good enough...If you need
to get around limitations of fully synchronzied methods and blocks (no
read/write policy, can't acquire/release locks from different methods,...)
then lock utilities are the way to go but at the cost of a more complicated
coding style. As for great Mutex primitives etc, I don't think you can
beat Doug Lea's util.concurrent package. There are also implementations of
a "SyncMap" where you can specify the type of lock you want to have on the
collection. He has placed this code in the public domain...
" Originally written by Doug Lea and released into the public domain.
This may be used for any purposes whatsoever without acknowledgment.
Thanks for the assistance and support of Sun Microsystems Labs,
and everyone contributing, testing, and using this code."
http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.h
tml
Regards,
Mark
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, August 09, 2000 3:06 PM
To: Turbine
Subject: Re: Refreshable Cache
"Paul O'Leary" <[EMAIL PROTECTED]> writes:
>
> I'll see if I can scare up a/o write some better synchronization
primitives.
>
Why not just the standard pattern for this ? What I usually use is
the pattern in the getCache() method in the code appended.
Regards,
Gunnar
/**
* The cache manager class acts as central registry for all
* object caches and can be used to expire/clean specific caches.
*/
public class CacheManager {
protected static Hashtable caches = new Hashtable();
/**
* Get a cache with the given name. This method will return
* a cache with the given name if it exists or create if doesn't already
* exist.
* @param name The unique name of the cache.
* @return Returns a cache with the given name.
*/
public static Cache getCache(String name){
Cache cache = (Cache) caches.get(name);
// Use the guard pattern to guard against concurrent threads
// trying to create a new cache at the same time. The code
// below ensures us that there will be only one Cache object with a
// given name.
if(cache == null){
synchronized(caches){
cache = (Cache) caches.get(name);
if(cache == null){
cache = new Cache();
caches.put(name, cache);
}
}
}
return cache;
}
}
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]