You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2009/06/17 18:48:35 UTC

svn commit: r785716 - /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java

Author: scheu
Date: Wed Jun 17 16:48:35 2009
New Revision: 785716

URL: http://svn.apache.org/viewvc?rev=785716&view=rev
Log:
Contributor:Rich Scheuerle and Davanum Srinivas
Summary:
Added some additional checkso to ParameterIncludeImpl to tolerate concurrency errors.
Even though the ParmaeterInclude map should be fully populated prior to use, some
users/scenarios have added properties to the map during execution.  These updates
are now tolerated with minimal performance degradation.

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java?rev=785716&r1=785715&r2=785716&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/ParameterIncludeImpl.java Wed Jun 17 16:48:35 2009
@@ -38,9 +38,13 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
+
 
 /**
  * Class ParameterIncludeImpl
@@ -84,13 +88,15 @@
     /**
      * Field parmeters
      */
-    protected final HashMap<String, Parameter> parameters;
+    protected Map<String, Parameter> parameters;
 
     /**
      * Constructor ParameterIncludeImpl.
      */
     public ParameterIncludeImpl() {
-        parameters = new HashMap<String, Parameter>();
+        // Use a capacity large enough to prevent
+        // resizing
+        parameters = new HashMap<String, Parameter>(64);
     }
 
     /**
@@ -102,6 +108,26 @@
         if (param != null) {
             synchronized (parameters) {
                 parameters.put(param.getName(), param);
+                try {
+                    parameters.put(param.getName(), param);
+                } catch (ConcurrentModificationException cme) {
+                    // The ParameteterIncludeImpl is supposed to be immutable after it is populated.
+                    // But alas, sometimes the callers forget and try to add new items.  If
+                    // this occurs, swap over to the slower ConcurrentHashMap and continue.
+                    if (log.isDebugEnabled()) {
+                        log.debug("ConcurrentModificationException Occured...changing to ConcurrentHashMap");
+                        log.debug("The exception is: " + cme);
+                    }
+
+                    Map newMap = new ConcurrentHashMap(parameters);
+                    newMap.put(param.getName(), param);
+                    parameters = newMap;
+                }
+
+                if (DEBUG_ENABLED) {
+                    this.debugParameterAdd(param);
+                }
+
             }
             
             if (DEBUG_ENABLED) {
@@ -112,8 +138,22 @@
 
     public void removeParameter(Parameter param) throws AxisFault {
         synchronized (parameters) {
-            parameters.remove(param.getName());
-        }
+            try {
+                parameters.remove(param.getName());
+            } catch (ConcurrentModificationException cme) {
+                // The ParameteterIncludeImpl is supposed to be immutable after it is populated.
+                // But alas, sometimes the callers forget and try to add new items.  If
+                // this occurs, swap over to the slower ConcurrentHashMap and continue.
+                if (log.isDebugEnabled()) {
+                    log.debug("ConcurrentModificationException Occured...changing to ConcurrentHashMap");
+                    log.debug("The exception is: " + cme);
+                }
+
+                Map newMap = new ConcurrentHashMap(parameters);
+                newMap.remove(param.getName());
+                parameters = newMap;
+            }
+        } 
     }
 
     /**
@@ -184,7 +224,9 @@
     }
 
     public ArrayList<Parameter> getParameters() {
-        return new ArrayList<Parameter>(parameters.values());
+        synchronized(parameters) {
+            return new ArrayList<Parameter>(parameters.values());
+        }
     }
 
     // to check whether the parameter is locked at any level