diff options
author | shuyangzhou | 2016-06-29 22:59:03 +0000 |
---|---|---|
committer | shuyangzhou | 2016-06-29 23:09:16 +0000 |
commit | 6abbd98c8bcb0d08e5105653a373f52416d03013 (patch) | |
tree | 9e6ebc9f4e0fc515123c187e4bf9e873aad91530 | |
parent | d682850d24f0a2e834ca254899f279176dff0ec9 (diff) | |
download | rt.equinox.bundles-6abbd98c8bcb0d08e5105653a373f52416d03013.tar.gz rt.equinox.bundles-6abbd98c8bcb0d08e5105653a373f52416d03013.tar.xz rt.equinox.bundles-6abbd98c8bcb0d08e5105653a373f52416d03013.zip |
LPS-66911 Better concurrency handling for inner sessions tracking.
Signed-off-by: shuyangzhou <shuyang.zhou@liferay.com>
-rw-r--r-- | bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java index f006afcb6..a9e740a13 100644 --- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java +++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionAdaptor.java @@ -14,6 +14,7 @@ package org.eclipse.equinox.http.servlet.internal.servlet; import java.io.Serializable; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import javax.servlet.ServletContext; import javax.servlet.http.*; import org.eclipse.equinox.http.servlet.internal.context.ContextController; @@ -27,7 +28,7 @@ public class HttpSessionAdaptor implements HttpSession, Serializable { private static final long serialVersionUID = 4626167646903550760L; private static final String PARENT_SESSION_LISTENER_KEY = "org.eclipse.equinox.http.parent.session.listener"; //$NON-NLS-1$ - transient final Set<HttpSessionAdaptor> innerSessions = new HashSet<HttpSessionAdaptor>(); + transient final Set<HttpSessionAdaptor> innerSessions = Collections.newSetFromMap(new ConcurrentHashMap<HttpSessionAdaptor, Boolean>()); @Override public void valueBound(HttpSessionBindingEvent event) { // do nothing @@ -37,14 +38,13 @@ public class HttpSessionAdaptor implements HttpSession, Serializable { public void valueUnbound(HttpSessionBindingEvent event) { // Here we assume the unbound event is signifying the session is being invalidated. // Must invalidate the inner sessions - Set<HttpSessionAdaptor> innerSessionsToInvalidate; - synchronized (innerSessions) { - // copy the sessions to invalidate and clear the set - innerSessionsToInvalidate = new HashSet<HttpSessionAdaptor>(innerSessions); - innerSessions.clear(); - } + Iterator<HttpSessionAdaptor> iterator = innerSessions.iterator(); + + while (iterator.hasNext()) { + HttpSessionAdaptor innerSession = iterator.next(); + + iterator.remove(); - for (HttpSessionAdaptor innerSession : innerSessionsToInvalidate) { ContextController contextController = innerSession.getController(); @@ -83,9 +83,8 @@ public class HttpSessionAdaptor implements HttpSession, Serializable { innerSession.getSession().setAttribute(PARENT_SESSION_LISTENER_KEY, parentListener); } } - synchronized (parentListener.innerSessions) { - parentListener.innerSessions.add(innerSession); - } + + parentListener.innerSessions.add(innerSession); } static void removeHttpSessionAdaptor(HttpSessionAdaptor innerSession) { @@ -95,9 +94,7 @@ public class HttpSessionAdaptor implements HttpSession, Serializable { parentListener = (ParentSessionListener) innerSession.getSession().getAttribute(PARENT_SESSION_LISTENER_KEY); } if (parentListener != null) { - synchronized (parentListener.innerSessions) { - parentListener.innerSessions.remove(innerSession); - } + parentListener.innerSessions.remove(innerSession); } } } |