Browse Source

Synchronized cache creation on CacheManager

Issue: SPR-11132
pull/423/head
Juergen Hoeller 12 years ago
parent
commit
de890fd100
  1. 4
      spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java

4
spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java vendored

@ -31,9 +31,9 @@ import net.sf.ehcache.constructs.blocking.SelfPopulatingCache;
import net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory; import net.sf.ehcache.constructs.blocking.UpdatingCacheEntryFactory;
import net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache; import net.sf.ehcache.constructs.blocking.UpdatingSelfPopulatingCache;
import net.sf.ehcache.event.CacheEventListener; import net.sf.ehcache.event.CacheEventListener;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@ -230,6 +230,7 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
this.cacheManager = CacheManager.getInstance(); this.cacheManager = CacheManager.getInstance();
} }
synchronized (this.cacheManager) {
// Fetch cache region: If none with the given name exists, create one on the fly. // Fetch cache region: If none with the given name exists, create one on the fly.
Ehcache rawCache; Ehcache rawCache;
boolean cacheExists = this.cacheManager.cacheExists(cacheName); boolean cacheExists = this.cacheManager.cacheExists(cacheName);
@ -271,6 +272,7 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea
} }
this.cache = decoratedCache; this.cache = decoratedCache;
} }
}
/** /**
* Create a raw Cache object based on the configuration of this FactoryBean. * Create a raw Cache object based on the configuration of this FactoryBean.

Loading…
Cancel
Save