Author: markt
Date: Tue Dec 16 21:51:33 2014
New Revision: 1646099

URL: http://svn.apache.org/r1646099
Log:
Switch to ConcurrentHashMap and remove syncs

Modified:
    tomcat/trunk/java/org/apache/catalina/authenticator/SingleSignOn.java

Modified: tomcat/trunk/java/org/apache/catalina/authenticator/SingleSignOn.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/authenticator/SingleSignOn.java?rev=1646099&r1=1646098&r2=1646099&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/authenticator/SingleSignOn.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/authenticator/SingleSignOn.java Tue 
Dec 16 21:51:33 2014
@@ -18,8 +18,8 @@ package org.apache.catalina.authenticato
 
 import java.io.IOException;
 import java.security.Principal;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.Cookie;
@@ -66,8 +66,7 @@ public class SingleSignOn extends ValveB
      * The cache of SingleSignOnEntry instances for authenticated Principals,
      * keyed by the cookie value that is used to select them.
      */
-    protected final Map<String,SingleSignOnEntry> cache = new HashMap<>();
-
+    protected final Map<String,SingleSignOnEntry> cache = new 
ConcurrentHashMap<>();
 
     /**
      * Indicates whether this valve should require a downstream Authenticator 
to
@@ -80,7 +79,7 @@ public class SingleSignOn extends ValveB
      * The cache of single sign on identifiers, keyed by the Session that is
      * associated with them.
      */
-    protected final Map<Session,String> reverse = new HashMap<>();
+    protected final Map<Session,String> reverse = new ConcurrentHashMap<>();
 
 
     /**
@@ -210,9 +209,7 @@ public class SingleSignOn extends ValveB
         }
 
         String ssoId = null;
-        synchronized (reverse) {
-            ssoId = reverse.get(session);
-        }
+        ssoId = reverse.get(session);
         if (ssoId == null) {
             return;
         }
@@ -359,10 +356,7 @@ public class SingleSignOn extends ValveB
         if (sso != null) {
             sso.addSession(this, session);
         }
-        synchronized (reverse) {
-            reverse.put(session, ssoId);
-        }
-
+        reverse.put(session, ssoId);
     }
 
 
@@ -375,9 +369,7 @@ public class SingleSignOn extends ValveB
      */
     protected void deregister(String ssoId, Session session) {
 
-        synchronized (reverse) {
-            reverse.remove(session);
-        }
+        reverse.remove(session);
 
         SingleSignOnEntry sso = lookup(ssoId);
         if (sso == null) {
@@ -389,11 +381,8 @@ public class SingleSignOn extends ValveB
         // see if we are the last session, if so blow away ssoId
         Session sessions[] = sso.findSessions();
         if (sessions == null || sessions.length == 0) {
-            synchronized (cache) {
-                cache.remove(ssoId);
-            }
+            cache.remove(ssoId);
         }
-
     }
 
 
@@ -410,10 +399,7 @@ public class SingleSignOn extends ValveB
         }
 
         // Look up and remove the corresponding SingleSignOnEntry
-        SingleSignOnEntry sso = null;
-        synchronized (cache) {
-            sso = cache.remove(ssoId);
-        }
+        SingleSignOnEntry sso = cache.remove(ssoId);
 
         if (sso == null) {
             return;
@@ -426,9 +412,7 @@ public class SingleSignOn extends ValveB
                 containerLog.trace(" Invalidating session " + sessions[i]);
             }
             // Remove from reverse cache first to avoid recursion
-            synchronized (reverse) {
-                reverse.remove(sessions[i]);
-            }
+            reverse.remove(sessions[i]);
             // Invalidate this session
             sessions[i].expire();
         }
@@ -509,11 +493,7 @@ public class SingleSignOn extends ValveB
                 (principal != null ? principal.getName() : "") + "' with auth 
type '" + authType + "'");
         }
 
-        synchronized (cache) {
-            cache.put(ssoId, new SingleSignOnEntry(principal, authType,
-                                                   username, password));
-        }
-
+        cache.put(ssoId, new SingleSignOnEntry(principal, authType, username, 
password));
     }
 
 
@@ -566,11 +546,7 @@ public class SingleSignOn extends ValveB
      * @param ssoId Single sign on identifier to look up
      */
     protected SingleSignOnEntry lookup(String ssoId) {
-
-        synchronized (cache) {
-            return cache.get(ssoId);
-        }
-
+        return cache.get(ssoId);
     }
 
 
@@ -598,9 +574,7 @@ public class SingleSignOn extends ValveB
         entry.removeSession(session);
 
         // Remove the inactive session from the 'reverse' Map.
-        synchronized(reverse) {
-            reverse.remove(session);
-        }
+        reverse.remove(session);
 
         // If there are not sessions left in the SingleSignOnEntry,
         // deregister the entry.



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

Reply via email to