You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2012/05/29 17:37:03 UTC
svn commit: r1343783 -
/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
Author: jacopoc
Date: Tue May 29 15:37:03 2012
New Revision: 1343783
URL: http://svn.apache.org/viewvc?rev=1343783&view=rev
Log:
Improved code that manages the cache:
* protected the UtilCache object (static field) by making it private and final
* removed unnecessary synchronization
* refactored code to be more inline with best practices for thread safefy: removed the method readNotificationGroups() (that was only used by the same class in one place) that was called with a lock held and inlined its logic into the colling method; this simplifies thecode and its readability
Modified:
ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java?rev=1343783&r1=1343782&r2=1343783&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/config/ServiceConfigUtil.java Tue May 29 15:37:03 2012
@@ -43,7 +43,7 @@ public class ServiceConfigUtil implement
public static final String module = ServiceConfigUtil.class.getName();
public static final String engine = "default";
public static final String SERVICE_ENGINE_XML_FILENAME = "serviceengine.xml";
- protected static UtilCache<String, Map<String, NotificationGroup>> notificationGroupCache = UtilCache.createUtilCache("service.NotificationGroups", 0, 0, false);
+ private static final UtilCache<String, Map<String, NotificationGroup>> notificationGroupCache = UtilCache.createUtilCache("service.NotificationGroups", 0, 0, false);
public static Element getXmlRootElement() throws GenericConfigException {
Element root = ResourceLoader.getXmlRootElement(ServiceConfigUtil.SERVICE_ENGINE_XML_FILENAME);
@@ -110,35 +110,22 @@ public class ServiceConfigUtil implement
return retryMin;
}
- public static void readNotificationGroups() {
- Element rootElement = null;
-
- try {
- rootElement = ServiceConfigUtil.getXmlRootElement();
- } catch (GenericConfigException e) {
- Debug.logError(e, "Error getting Service Engine XML root element", module);
- }
-
- FastMap<String, NotificationGroup> engineNotifyMap = FastMap.newInstance();
-
- for (Element e: UtilXml.childElementList(rootElement, "notification-group")) {
- NotificationGroup ng = new NotificationGroup(e);
- engineNotifyMap.put(ng.getName(), ng);
- }
-
- notificationGroupCache.put(engine, engineNotifyMap);
- }
-
public static NotificationGroup getNotificationGroup(String group) {
Map<String, NotificationGroup> engineNotifyMap = notificationGroupCache.get(engine);
if (engineNotifyMap == null) {
- synchronized(ServiceConfigUtil.class) {
- engineNotifyMap = notificationGroupCache.get(engine);
- if (engineNotifyMap == null) {
- readNotificationGroups();
- }
+ //
+ Element rootElement = null;
+ try {
+ rootElement = ServiceConfigUtil.getXmlRootElement();
+ } catch (GenericConfigException e) {
+ Debug.logError(e, "Error getting Service Engine XML root element", module);
+ }
+ engineNotifyMap = FastMap.newInstance();
+ for (Element e: UtilXml.childElementList(rootElement, "notification-group")) {
+ NotificationGroup ng = new NotificationGroup(e);
+ engineNotifyMap.put(ng.getName(), ng);
}
- engineNotifyMap = notificationGroupCache.get(engine);
+ engineNotifyMap = notificationGroupCache.putIfAbsentAndGet(engine, engineNotifyMap);
}
if (engineNotifyMap != null) {
return engineNotifyMap.get(group);