TOMEE-1577 synchronizing httpsessionimpl invalidate

Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/10280fab
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/10280fab
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/10280fab

Branch: refs/heads/master
Commit: 10280fab2fdf8b452bf44db81d1b7bdeb9096571
Parents: 64febe3
Author: Romain Manni-Bucau <[email protected]>
Authored: Tue May 5 09:49:47 2015 +0200
Committer: Romain Manni-Bucau <[email protected]>
Committed: Tue May 5 09:49:47 2015 +0200

----------------------------------------------------------------------
 .../openejb/server/httpd/HttpSessionImpl.java   | 34 +++++++++++++-------
 1 file changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/10280fab/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
----------------------------------------------------------------------
diff --git 
a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
 
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
index f82b7bf..104deb5 100644
--- 
a/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
+++ 
b/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/HttpSessionImpl.java
@@ -40,6 +40,7 @@ public class HttpSessionImpl implements HttpSession {
     private final long created = System.currentTimeMillis();
     private volatile long timeout;
     private volatile long lastAccessed = created;
+    private volatile boolean valid = true;
 
     public HttpSessionImpl(final String contextPath, final long timeout) {
         this.timeout = timeout;
@@ -91,20 +92,31 @@ public class HttpSessionImpl implements HttpSession {
 
     @Override
     public void invalidate() {
-        if (!listeners.isEmpty()) {
-            final HttpSessionEvent event = new HttpSessionEvent(this);
-            for (final HttpSessionListener o : listeners) {
-                try {
-                    HttpSessionListener.class.cast(o).sessionDestroyed(event);
-                } catch (final Throwable th) {
-                    // ignore, may be undeployed
+        if (!valid) {
+            return;
+        }
+
+        synchronized (this) {
+            if (!valid) {
+                return;
+            }
+
+            if (!listeners.isEmpty()) {
+                final HttpSessionEvent event = new HttpSessionEvent(this);
+                for (final HttpSessionListener o : listeners) {
+                    try {
+                        
HttpSessionListener.class.cast(o).sessionDestroyed(event);
+                    } catch (final Throwable th) {
+                        // ignore, may be undeployed
+                    }
                 }
             }
-        }
 
-        final SessionManager sessionManager = 
SystemInstance.get().getComponent(SessionManager.class);
-        if (sessionManager != null) {
-            sessionManager.removeSession(sessionId);
+            final SessionManager sessionManager = 
SystemInstance.get().getComponent(SessionManager.class);
+            if (sessionManager != null) {
+                sessionManager.removeSession(sessionId);
+            }
+            valid = false;
         }
     }
 

Reply via email to