You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2006/07/25 16:19:33 UTC

svn commit: r425399 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina: core/ApplicationContext.java session/ManagerBase.java session/StandardManager.java session/StandardSession.java

Author: remm
Date: Tue Jul 25 07:19:32 2006
New Revision: 425399

URL: http://svn.apache.org/viewvc?rev=425399&view=rev
Log:
- Experiment with using concurrent maps in places which may be concurrently accessed.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/ManagerBase.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardManager.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=425399&r1=425398&r2=425399&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java Tue Jul 25 07:19:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,9 +24,10 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.naming.Binding;
 import javax.naming.NamingException;
@@ -87,13 +88,13 @@
     /**
      * The context attributes for this context.
      */
-    private HashMap attributes = new HashMap();
+    private Map attributes = new ConcurrentHashMap();
 
 
     /**
      * List of read only attributes for this context.
      */
-    private HashMap readOnlyAttributes = new HashMap();
+    private Map readOnlyAttributes = new ConcurrentHashMap();
 
 
     /**
@@ -118,7 +119,7 @@
     /**
      * The merged context initialization parameters for this Context.
      */
-    private HashMap parameters = null;
+    private Map parameters = null;
 
 
     /**
@@ -172,9 +173,7 @@
      */
     public Object getAttribute(String name) {
 
-        synchronized (attributes) {
-            return (attributes.get(name));
-        }
+        return (attributes.get(name));
 
     }
 
@@ -185,9 +184,7 @@
      */
     public Enumeration getAttributeNames() {
 
-        synchronized (attributes) {
-            return new Enumerator(attributes.keySet(), true);
-        }
+        return new Enumerator(attributes.keySet(), true);
 
     }
 
@@ -258,9 +255,8 @@
     public String getInitParameter(final String name) {
 
         mergeParameters();
-        synchronized (parameters) {
-            return ((String) parameters.get(name));
-        }
+        return ((String) parameters.get(name));
+
     }
 
 
@@ -271,9 +267,7 @@
     public Enumeration getInitParameterNames() {
 
         mergeParameters();
-        synchronized (parameters) {
-           return (new Enumerator(parameters.keySet()));
-        }
+        return (new Enumerator(parameters.keySet()));
 
     }
 
@@ -688,17 +682,15 @@
         boolean found = false;
 
         // Remove the specified attribute
-        synchronized (attributes) {
-            // Check for read only attribute
-           if (readOnlyAttributes.containsKey(name))
-                return;
-            found = attributes.containsKey(name);
-            if (found) {
-                value = attributes.get(name);
-                attributes.remove(name);
-            } else {
-                return;
-            }
+        // Check for read only attribute
+        if (readOnlyAttributes.containsKey(name))
+            return;
+        found = attributes.containsKey(name);
+        if (found) {
+            value = attributes.get(name);
+            attributes.remove(name);
+        } else {
+            return;
         }
 
         // Notify interested application event listeners
@@ -754,15 +746,13 @@
         boolean replaced = false;
 
         // Add or replace the specified attribute
-        synchronized (attributes) {
-            // Check for read only attribute
-            if (readOnlyAttributes.containsKey(name))
-                return;
-            oldValue = attributes.get(name);
-            if (oldValue != null)
-                replaced = true;
-            attributes.put(name, value);
-        }
+        // Check for read only attribute
+        if (readOnlyAttributes.containsKey(name))
+            return;
+        oldValue = attributes.get(name);
+        if (oldValue != null)
+            replaced = true;
+        attributes.put(name, value);
 
         // Notify interested application event listeners
         Object listeners[] = context.getApplicationEventListeners();
@@ -822,11 +812,9 @@
 
         // Create list of attributes to be removed
         ArrayList list = new ArrayList();
-        synchronized (attributes) {
-            Iterator iter = attributes.keySet().iterator();
-            while (iter.hasNext()) {
-                list.add(iter.next());
-            }
+        Iterator iter = attributes.keySet().iterator();
+        while (iter.hasNext()) {
+            list.add(iter.next());
         }
 
         // Remove application originated attributes
@@ -855,10 +843,8 @@
      */
     void setAttributeReadOnly(String name) {
 
-        synchronized (attributes) {
-            if (attributes.containsKey(name))
-                readOnlyAttributes.put(name, name);
-        }
+        if (attributes.containsKey(name))
+            readOnlyAttributes.put(name, name);
 
     }
 
@@ -915,7 +901,7 @@
 
         if (parameters != null)
             return;
-        HashMap results = new HashMap();
+        Map results = new ConcurrentHashMap();
         String names[] = context.findParameters();
         for (int i = 0; i < names.length; i++)
             results.put(names[i], context.findParameter(names[i]));

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/ManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/ManagerBase.java?rev=425399&r1=425398&r2=425399&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/ManagerBase.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/ManagerBase.java Tue Jul 25 07:19:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,7 +33,9 @@
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
@@ -171,7 +173,7 @@
      * The set of currently active Sessions for this Manager, keyed by
      * session identifier.
      */
-    protected HashMap sessions = new HashMap();
+    protected Map sessions = new ConcurrentHashMap();
 
     // Number of sessions created by this manager
     protected int sessionCounter=0;
@@ -731,11 +733,10 @@
      */
     public void add(Session session) {
 
-        synchronized (sessions) {
-            sessions.put(session.getIdInternal(), session);
-            if( sessions.size() > maxActive ) {
-                maxActive=sessions.size();
-            }
+        sessions.put(session.getIdInternal(), session);
+        int size = sessions.size();
+        if( size > maxActive ) {
+            maxActive = size;
         }
     }
 
@@ -854,10 +855,7 @@
 
         if (id == null)
             return (null);
-        synchronized (sessions) {
-            Session session = (Session) sessions.get(id);
-            return (session);
-        }
+        return (Session) sessions.get(id);
 
     }
 
@@ -885,9 +883,7 @@
      */
     public void remove(Session session) {
 
-        synchronized (sessions) {
-            sessions.remove(session.getIdInternal());
-        }
+        sessions.remove(session.getIdInternal());
 
     }
 
@@ -1134,8 +1130,8 @@
      */
     public String listSessionIds() {
         StringBuffer sb=new StringBuffer();
-        Iterator keys=sessions.keySet().iterator();
-        while( keys.hasNext() ) {
+        Iterator keys = sessions.keySet().iterator();
+        while (keys.hasNext()) {
             sb.append(keys.next()).append(" ");
         }
         return sb.toString();
@@ -1150,7 +1146,7 @@
      * @return The attribute value, if found, null otherwise
      */
     public String getSessionAttribute( String sessionId, String key ) {
-        Session s=(Session)sessions.get(sessionId);
+        Session s = (Session) sessions.get(sessionId);
         if( s==null ) {
             if(log.isInfoEnabled())
                 log.info("Session not found " + sessionId);

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardManager.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardManager.java?rev=425399&r1=425398&r2=425399&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardManager.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardManager.java Tue Jul 25 07:19:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.

Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java?rev=425399&r1=425398&r2=425399&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java Tue Jul 25 07:19:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999,2004 The Apache Software Foundation.
+ * Copyright 1999,2004-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.servlet.ServletContext;
@@ -122,7 +123,7 @@
     /**
      * The collection of user data attributes associated with this Session.
      */
-    protected Map attributes = new Hashtable();
+    protected Map attributes = new ConcurrentHashMap();
 
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org