All,
I was looking at AXIS2-3283 which propted me to take a look at the
operationContextMap in ConfigurationContext and it struck me that we
can probably do better than the current synchronization blocks by
using a ConcurrentHashMap.
I 've attached a patch to make this change. Could someone take a look
and sanity check it please?

David
-- 
David Illsley - IBM Web Services Development
Index: E:/work/workspaces/opensource/axis2/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java
===================================================================
--- E:/work/workspaces/opensource/axis2/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java	(revision 609973)
+++ E:/work/workspaces/opensource/axis2/modules/kernel/src/org/apache/axis2/context/ConfigurationContext.java	(working copy)
@@ -40,6 +40,8 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
@@ -70,7 +72,7 @@
      * Map containing <code>MessageID</code> to
      * <code>OperationContext</code> mapping.
      */
-    private final Map operationContextMap = new HashMap();
+    private final ConcurrentHashMap operationContextMap = new ConcurrentHashMap();
     private Hashtable serviceGroupContextMap = new Hashtable();
     private Hashtable applicationSessionServiceGroupContexts = new Hashtable();
     private AxisConfiguration axisConfiguration;
@@ -309,27 +311,27 @@
     public boolean registerOperationContext(String messageID, 
                                             OperationContext mepContext, 
                                             boolean override) {
-        boolean alreadyInMap;
+        boolean alreadyInMap = false;
         mepContext.setKey(messageID);
-        synchronized (operationContextMap) {
-            alreadyInMap = operationContextMap.containsKey(messageID);
-            if (!alreadyInMap || override) {
-                this.operationContextMap.put(messageID, mepContext);
-            }
 
-            if (log.isDebugEnabled())
-            {
-                log.debug("registerOperationContext ("+override+"): "+
-                          mepContext+" with key: "+messageID);
-                HashMap msgContextMap = mepContext.getMessageContexts();
-                Iterator msgContextIterator = msgContextMap.values().iterator();
-                while (msgContextIterator.hasNext())
-                {
-                    MessageContext msgContext = (MessageContext)msgContextIterator.next();
-                    log.debug("msgContext: "+msgContext+" action: "+msgContext.getWSAAction());
-                }
-            }
+        if(override){
+        	operationContextMap.put(messageID, mepContext);
+        }else{
+        	Object previous = operationContextMap.putIfAbsent(messageID, mepContext);
+        	alreadyInMap = (previous!=null);
         }
+        if (log.isDebugEnabled())
+        {
+        	log.debug("registerOperationContext ("+override+"): "+
+        			mepContext+" with key: "+messageID);
+        	HashMap msgContextMap = mepContext.getMessageContexts();
+        	Iterator msgContextIterator = msgContextMap.values().iterator();
+        	while (msgContextIterator.hasNext())
+        	{
+        		MessageContext msgContext = (MessageContext)msgContextIterator.next();
+        		log.debug("msgContext: "+msgContext+" action: "+msgContext.getWSAAction());
+        	}
+        }
         return (!alreadyInMap || override);
     }
     /**
@@ -338,11 +340,8 @@
      * @param key
      */
     public void unregisterOperationContext(String key) {
-        synchronized (operationContextMap) {
-            OperationContext opCtx = (OperationContext) operationContextMap.get(key);
-            operationContextMap.remove(key);
-            contextRemoved(opCtx);
-        }
+    	OperationContext opCtx = (OperationContext) operationContextMap.remove(key);
+    	contextRemoved(opCtx);
     }
 
     /**
@@ -402,14 +401,7 @@
      * @param id
      */
     public OperationContext getOperationContext(String id) {
-        OperationContext opCtx;
-        synchronized (operationContextMap) {
-            if (operationContextMap == null) {
-                return null;
-            }
-            opCtx = (OperationContext) this.operationContextMap.get(id);
-        }
-
+        OperationContext opCtx = (OperationContext) this.operationContextMap.get(id);
         return opCtx;
     }
 
@@ -434,39 +426,36 @@
         // group name is not necessarily a prereq
         // but if the group name is non-null, then it has to match
 
-        synchronized (operationContextMap) {
-            Iterator it = operationContextMap.keySet().iterator();
+        Iterator it = operationContextMap.values().iterator();
 
-            while (it.hasNext()) {
-                Object key = it.next();
-                OperationContext value = (OperationContext) operationContextMap.get(key);
+        while (it.hasNext()) {
+        	OperationContext value = (OperationContext) it.next();
 
-                String valueOperationName;
-                String valueServiceName;
-                String valueServiceGroupName;
+        	String valueOperationName;
+        	String valueServiceName;
+        	String valueServiceGroupName;
 
-                if (value != null) {
-                    valueOperationName = value.getOperationName();
-                    valueServiceName = value.getServiceName();
-                    valueServiceGroupName = value.getServiceGroupName();
+        	if (value != null) {
+        		valueOperationName = value.getOperationName();
+        		valueServiceName = value.getServiceName();
+        		valueServiceGroupName = value.getServiceGroupName();
 
-                    if ((valueOperationName != null) && (valueOperationName.equals(operationName))) {
-                        if ((valueServiceName != null) && (valueServiceName.equals(serviceName))) {
-                            if ((valueServiceGroupName != null) && (serviceGroupName != null)
-                                && (valueServiceGroupName.equals(serviceGroupName))) {
-                                // match
-                                return value;
-                            }
+        		if ((valueOperationName != null) && (valueOperationName.equals(operationName))) {
+        			if ((valueServiceName != null) && (valueServiceName.equals(serviceName))) {
+        				if ((valueServiceGroupName != null) && (serviceGroupName != null)
+        						&& (valueServiceGroupName.equals(serviceGroupName))) {
+        					// match
+        					return value;
+        				}
 
-                            // or, both need to be null
-                            if ((valueServiceGroupName == null) && (serviceGroupName == null)) {
-                                // match
-                                return value;
-                            }
-                        }
-                    }
-                }
-            }
+        				// or, both need to be null
+        				if ((valueServiceGroupName == null) && (serviceGroupName == null)) {
+        					// match
+        					return value;
+        				}
+        			}
+        		}
+        	}
         }
 
         // if we got here, we did not find an operation context
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to