tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1507796 - in /tomee/tomee/trunk: container/openejb-core/src/main/java/org/apache/openejb/cdi/ server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/ server/openejb-http/src/main/java/org/apache/openejb/server/httpd/ tomee/to...
Date Sun, 28 Jul 2013 13:04:52 GMT
Author: rmannibucau
Date: Sun Jul 28 13:04:52 2013
New Revision: 1507796

URL: http://svn.apache.org/r1507796
Log:
TOMEE-1009 better handling of request thread local cleaning

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
    tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
    tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
    tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/cdi/SessionNormalScopeBeanHandler.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java?rev=1507796&r1=1507795&r2=1507796&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
Sun Jul 28 13:04:52 2013
@@ -49,6 +49,8 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpSession;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Collection;
 
 public class CdiAppContextsService extends AbstractContextsService implements ContextsService
{
 
@@ -72,6 +74,14 @@ public class CdiAppContextsService exten
 
     private final WebBeansContext webBeansContext;
 
+    private static final ThreadLocal<Collection<Runnable>> endRequestRunnables
= new ThreadLocal<Collection<Runnable>>() {
+        @Override
+        protected Collection<Runnable> initialValue() {
+            return new ArrayList<Runnable>();
+        }
+    };
+
+
     public CdiAppContextsService() {
         this(WebBeansContext.currentInstance(), WebBeansContext.currentInstance().getOpenWebBeansConfiguration().supportsConversation());
     }
@@ -93,6 +103,21 @@ public class CdiAppContextsService exten
         singletonContext.setActive(true);
     }
 
+    private void endRequest() {
+        for (final Runnable r : endRequestRunnables.get()) {
+            try {
+                r.run();
+            } catch (final Exception e) {
+                logger.error(e.getMessage(), e);
+            }
+        }
+        endRequestRunnables.remove();
+    }
+
+    public static void pushRequestReleasable(final Runnable runnable) {
+        endRequestRunnables.get().add(runnable);
+    }
+
     @Override
     public void init(Object initializeObject) {
         //Start application context
@@ -237,12 +262,15 @@ public class CdiAppContextsService exten
     }
 
     private void destroyRequestContext() {
+        // execute request tasks
+        endRequest();
+
         if (supportsConversation()) { // OWB-595
             cleanupConversation();
         }
 
         //Get context
-        RequestContext context = getRequestContext();
+        final RequestContext context = getRequestContext();
 
         //Destroy context
         if (context != null) {
@@ -250,7 +278,7 @@ public class CdiAppContextsService exten
         }
 
         // clean up the EL caches after each request
-        ELContextStore elStore = ELContextStore.getInstance(false);
+        final ELContextStore elStore = ELContextStore.getInstance(false);
         if (elStore != null) {
             elStore.destroyELContextStore();
         }

Modified: tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java?rev=1507796&r1=1507795&r2=1507796&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
(original)
+++ tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/Contexts.java
Sun Jul 28 13:04:52 2013
@@ -24,8 +24,8 @@ import org.apache.cxf.jaxrs.utils.Annota
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
+import org.apache.openejb.cdi.CdiAppContextsService;
 import org.apache.openejb.rest.ThreadLocalContextManager;
-import org.apache.openejb.server.httpd.EndWebBeansListener;
 
 import javax.annotation.Resource;
 import javax.servlet.ServletConfig;
@@ -98,7 +98,7 @@ public final class Contexts {
      */
     public static void bind(Exchange exchange, Collection<Class<?>> types) {
         EXCHANGE.set(exchange); // used in lazy mode by RESTResourceFinder if cdi beans uses
@Context, === initThreadLocal
-        EndWebBeansListener.pushRequestReleasable(CleanUpThreadLocal.INSTANCE);
+        CdiAppContextsService.pushRequestReleasable(CleanUpThreadLocal.INSTANCE);
 
         for (Class<?> type : types) {
             if (Request.class.equals(type)) {

Modified: tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java?rev=1507796&r1=1507795&r2=1507796&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
(original)
+++ tomee/tomee/trunk/server/openejb-http/src/main/java/org/apache/openejb/server/httpd/EndWebBeansListener.java
Sun Jul 28 13:04:52 2013
@@ -49,12 +49,6 @@ public class EndWebBeansListener impleme
      * Logger instance
      */
     private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_CDI, EndWebBeansListener.class);
-    private static final ThreadLocal<Collection<Runnable>> endRequestRunnables
= new ThreadLocal<Collection<Runnable>>() {
-        @Override
-        protected Collection<Runnable> initialValue() {
-            return new ArrayList<Runnable>();
-        }
-    };
 
     protected FailOverService failoverService;
 
@@ -79,31 +73,11 @@ public class EndWebBeansListener impleme
     }
 
     /**
-     * Ensures that all ThreadLocals, which could have been set in this
-     * request's Thread, are removed in order to prevent memory leaks.
-     */
-    private void cleanupRequestThreadLocals() {
-        for (final Runnable r : endRequestRunnables.get()) {
-            try {
-                r.run();
-            } catch (final Exception e) {
-                logger.error(e.getMessage(), e);
-            }
-        }
-        endRequestRunnables.remove();
-    }
-
-    public static void pushRequestReleasable(final Runnable runnable) {
-        endRequestRunnables.get().add(runnable);
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
     public void requestDestroyed(ServletRequestEvent event) {
         if (webBeansContext == null) {
-            cleanupRequestThreadLocals();
             return;
         }
 
@@ -136,7 +110,6 @@ public class EndWebBeansListener impleme
             if (webBeansContext instanceof WebappWebBeansContext) { // end after child
                 ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().endContext(RequestScoped.class,
event);
             }
-            cleanupRequestThreadLocals();
         } finally {
             ThreadSingletonServiceImpl.enter((WebBeansContext) oldContext);
         }

Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/cdi/SessionNormalScopeBeanHandler.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/cdi/SessionNormalScopeBeanHandler.java?rev=1507796&r1=1507795&r2=1507796&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/cdi/SessionNormalScopeBeanHandler.java
(original)
+++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/cdi/SessionNormalScopeBeanHandler.java
Sun Jul 28 13:04:52 2013
@@ -16,7 +16,7 @@
  */
 package org.apache.tomee.catalina.cdi;
 
-import org.apache.openejb.server.httpd.EndWebBeansListener;
+import org.apache.openejb.cdi.CdiAppContextsService;
 import org.apache.tomee.catalina.TomEERuntimeException;
 import org.apache.webbeans.context.creational.BeanInstanceBag;
 import org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler;
@@ -44,7 +44,7 @@ public class SessionNormalScopeBeanHandl
     private final ThreadLocal<Map<Bean<?>, UpdateInfo>> objects = new ThreadLocal<Map<Bean<?>,
UpdateInfo>>() {
         @Override
         protected Map<Bean<?>, UpdateInfo> initialValue() {
-            EndWebBeansListener.pushRequestReleasable(new Runnable() { // update in batch
+            CdiAppContextsService.pushRequestReleasable(new Runnable() { // update in batch
                 @Override
                 public void run() {
                     final Map<Bean<?>, UpdateInfo> values = objects.get();



Mime
View raw message