Author: jacopoc
Date: Mon May 28 15:02:39 2012
New Revision: 1343277
URL:
http://svn.apache.org/viewvc?rev=1343277&view=revLog:
Improved code that manages the cache:
* removed unnecessary synchronization
* protected the UtilCache object (static field) by making it private and final
Modified:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/region/RegionManager.java
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/region/RegionManager.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/region/RegionManager.java?rev=1343277&r1=1343276&r2=1343277&view=diff==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/region/RegionManager.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/region/RegionManager.java Mon May 28 15:02:39 2012
@@ -38,7 +38,7 @@ public class RegionManager {
public static final String module = RegionManager.class.getName();
- protected static UtilCache<URL, Map<String, Region>> regionCache = UtilCache.createUtilCache("webapp.Regions.Config", 0, 0);
+ private static final UtilCache<URL, Map<String, Region>> regionCache = UtilCache.createUtilCache("webapp.Regions.Config", 0, 0);
protected URL regionFile = null;
@@ -54,14 +54,8 @@ public class RegionManager {
public Map<String, Region> getRegions() {
Map<String, Region> regions = regionCache.get(regionFile);
if (regions == null) {
- synchronized (this) {
- regions = regionCache.get(regionFile);
- if (regions == null) {
- if (Debug.verboseOn()) Debug.logVerbose("Regions not loaded for " + regionFile + ", loading now", module);
- regions = readRegionXml(regionFile);
- regionCache.put(regionFile, regions);
- }
- }
+ if (Debug.verboseOn()) Debug.logVerbose("Regions not loaded for " + regionFile + ", loading now", module);
+ regions = regionCache.putIfAbsentAndGet(regionFile, readRegionXml(regionFile));
}
return regions;
}