"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]

Reply via email to