@@ -316,46 +316,48 @@ public void afterPropertiesSet() throws CacheException, IOException {
316
316
this .cacheName = this .beanName ;
317
317
}
318
318
319
- // Fetch cache region: If none with the given name exists,
320
- // create one on the fly.
321
- Ehcache rawCache ;
322
- boolean cacheExists = this .cacheManager .cacheExists (cacheName );
323
- if (cacheExists ) {
324
- if (logger .isDebugEnabled ()) {
325
- logger .debug ("Using existing EhCache cache region '" + this .cacheName + "'" );
319
+ synchronized (this .cacheManager ) {
320
+ // Fetch cache region: If none with the given name exists,
321
+ // create one on the fly.
322
+ Ehcache rawCache ;
323
+ boolean cacheExists = this .cacheManager .cacheExists (this .cacheName );
324
+ if (cacheExists ) {
325
+ if (logger .isDebugEnabled ()) {
326
+ logger .debug ("Using existing EhCache cache region '" + this .cacheName + "'" );
327
+ }
328
+ rawCache = this .cacheManager .getEhcache (this .cacheName );
326
329
}
327
- rawCache = this . cacheManager . getEhcache ( this . cacheName );
328
- }
329
- else {
330
- if ( logger . isDebugEnabled ()) {
331
- logger . debug ( "Creating new EhCache cache region '" + this . cacheName + "'" );
330
+ else {
331
+ if ( logger . isDebugEnabled ()) {
332
+ logger . debug ( "Creating new EhCache cache region '" + this . cacheName + "'" );
333
+ }
334
+ rawCache = createCache ( );
332
335
}
333
- rawCache = createCache ();
334
- }
335
336
336
- if (this .cacheEventListeners != null ) {
337
- for (CacheEventListener listener : this .cacheEventListeners ) {
338
- rawCache .getCacheEventNotificationService ().registerListener (listener );
337
+ if (this .cacheEventListeners != null ) {
338
+ for (CacheEventListener listener : this .cacheEventListeners ) {
339
+ rawCache .getCacheEventNotificationService ().registerListener (listener );
340
+ }
341
+ }
342
+ if (this .statisticsEnabled ) {
343
+ rawCache .setStatisticsEnabled (true );
344
+ }
345
+ if (this .sampledStatisticsEnabled ) {
346
+ rawCache .setSampledStatisticsEnabled (true );
347
+ }
348
+ if (this .disabled ) {
349
+ rawCache .setDisabled (true );
339
350
}
340
- }
341
- if (this .statisticsEnabled ) {
342
- rawCache .setStatisticsEnabled (true );
343
- }
344
- if (this .sampledStatisticsEnabled ) {
345
- rawCache .setSampledStatisticsEnabled (true );
346
- }
347
- if (this .disabled ) {
348
- rawCache .setDisabled (true );
349
- }
350
351
351
- if (!cacheExists ) {
352
- this .cacheManager .addCache (rawCache );
353
- }
354
- Ehcache decoratedCache = decorateCache (rawCache );
355
- if (decoratedCache != rawCache ) {
356
- this .cacheManager .replaceCacheWithDecoratedCache (rawCache , decoratedCache );
352
+ if (!cacheExists ) {
353
+ this .cacheManager .addCache (rawCache );
354
+ }
355
+ Ehcache decoratedCache = decorateCache (rawCache );
356
+ if (decoratedCache != rawCache ) {
357
+ this .cacheManager .replaceCacheWithDecoratedCache (rawCache , decoratedCache );
358
+ }
359
+ this .cache = decoratedCache ;
357
360
}
358
- this .cache = decoratedCache ;
359
361
}
360
362
361
363
/**
0 commit comments