From 2783d31ca2f2550117986647915dda283d520068 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 14 Feb 2008 18:55:21 +0000 Subject: [PATCH] We need to guard against simultaneous calls to getCache(). --- .../samskivert/jdbc/depot/EHCacheAdapter.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/java/com/samskivert/jdbc/depot/EHCacheAdapter.java b/src/java/com/samskivert/jdbc/depot/EHCacheAdapter.java index ed263bf..535de9c 100644 --- a/src/java/com/samskivert/jdbc/depot/EHCacheAdapter.java +++ b/src/java/com/samskivert/jdbc/depot/EHCacheAdapter.java @@ -106,25 +106,26 @@ public class EHCacheAdapter protected EHCacheBin (String id) { - _cache = _cachemgr.getCache(id); - if (_cache == null) { - // create the cache programatically with reasonable settings - // TODO: we will eventually need this to be configurable in .properties + synchronized (_cachemgr) { + _cache = _cachemgr.getCache(id); + if (_cache == null) { + // create the cache programatically with reasonable settings + // TODO: we will eventually need this to be configurable in .properties + _cache = new Cache(id, + 5000, // keep 5000 elements in RAM + true, // overflow the rest to disk + false, // don't keep records around eternally + 600, // keep them for 10 minutes after they're created + 60); // or 1 minute after last access - _cache = new Cache(id, - 5000, // keep 5000 elements in RAM - true, // overflow the rest to disk - false, // don't keep records around eternally - 600, // but do keep them for 10 minutes after they're created - 60); // or 1 minute after last access - - if (_distributed) { - // a programatically created cache has to have its replicator event listener - // programatically added. - _cache.getCacheEventNotificationService().registerListener( - new RMIAsynchronousCacheReplicator(true, true, true, true, 1000)); + if (_distributed) { + // a programatically created cache has to have its replicator event + // listener programatically added. + _cache.getCacheEventNotificationService().registerListener( + new RMIAsynchronousCacheReplicator(true, true, true, true, 1000)); + } + _cachemgr.addCache(_cache); } - _cachemgr.addCache(_cache); } }