openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1003138 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/component/ webbeans-web/src/main/java/org/apache/webbeans/servlet/ webbeans-web/src/main/java/org/apache/webbeans/web/context/ webbeans-web/src/main/java/org...
Date Thu, 30 Sep 2010 16:20:23 GMT
Author: struberg
Date: Thu Sep 30 16:20:23 2010
New Revision: 1003138

URL: http://svn.apache.org/viewvc?rev=1003138&view=rev
Log:
OWB-466 Ensure removal of all ThreadLocal values

apply patch submitted by jakobk@apache.org, thanks m8!

This problems happens most of the times when shutting down the container.
This is a problem if only single webapps are being restarted.

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java?rev=1003138&r1=1003137&r2=1003138&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionPointBean.java
Thu Sep 30 16:20:23 2010
@@ -18,18 +18,26 @@
  */
 package org.apache.webbeans.component;
 
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.InjectionPoint;
-
 import org.apache.webbeans.annotation.DefaultLiteral;
 import org.apache.webbeans.annotation.DependentScopeLiteral;
 
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+
 
 public class InjectionPointBean extends AbstractOwbBean<InjectionPoint>
 {
     // TODO refactor. public static variables are uterly ugly
     public static ThreadLocal<InjectionPoint> local = new ThreadLocal<InjectionPoint>();
-    
+
+    /**
+     * Removes the ThreadLocal from the ThreadMap to prevent memory leaks.
+     */
+    public static void removeThreadLocal()
+    {
+        local.remove();
+    }
+
     public InjectionPointBean()
     {
         super(WebBeansType.INJECTIONPOINT,InjectionPoint.class);

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java?rev=1003138&r1=1003137&r2=1003138&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/servlet/WebBeansConfigurationListener.java
Thu Sep 30 16:20:23 2010
@@ -18,6 +18,19 @@
  */
 package org.apache.webbeans.servlet;
 
+import org.apache.webbeans.component.InjectionPointBean;
+import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.conversation.ConversationManager;
+import org.apache.webbeans.corespi.ServiceLoader;
+import org.apache.webbeans.el.ELContextStore;
+import org.apache.webbeans.lifecycle.LifecycleFactory;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.spi.ContainerLifecycle;
+import org.apache.webbeans.spi.FailOverService;
+import org.apache.webbeans.util.WebBeansUtil;
+import org.apache.webbeans.web.context.WebContextsService;
+
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.SessionScoped;
 import javax.servlet.ServletContextEvent;
@@ -30,17 +43,6 @@ import javax.servlet.http.HttpSessionAct
 import javax.servlet.http.HttpSessionEvent;
 import javax.servlet.http.HttpSessionListener;
 
-import org.apache.webbeans.config.OWBLogConst;
-import org.apache.webbeans.config.OpenWebBeansConfiguration;
-import org.apache.webbeans.conversation.ConversationManager;
-import org.apache.webbeans.corespi.ServiceLoader;
-import org.apache.webbeans.el.ELContextStore;
-import org.apache.webbeans.lifecycle.LifecycleFactory;
-import org.apache.webbeans.logger.WebBeansLogger;
-import org.apache.webbeans.spi.ContainerLifecycle;
-import org.apache.webbeans.spi.FailOverService;
-import org.apache.webbeans.util.WebBeansUtil;
-
 /**
  * Initializing the beans container for using in an web application
  * environment.
@@ -129,6 +131,20 @@ public class WebBeansConfigurationListen
         }
 
         this.lifeCycle.getContextService().endContext(RequestScoped.class, event);
+
+        this.cleanupRequestThreadLocals();
+    }
+
+    /**
+     * 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()
+    {
+        // TODO maybe there are more to cleanup
+
+        InjectionPointBean.removeThreadLocal();
+        WebContextsService.removeThreadLocals();
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1003138&r1=1003137&r2=1003138&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Thu Sep 30 16:20:23 2010
@@ -18,23 +18,6 @@
  */
 package org.apache.webbeans.web.context;
 
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.ContextException;
-import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.context.spi.Context;
-import javax.inject.Singleton;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequestEvent;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
-
 import org.apache.webbeans.config.OWBLogConst;
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.context.AbstractContextsService;
@@ -50,6 +33,22 @@ import org.apache.webbeans.el.ELContextS
 import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.spi.FailOverService;
 
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.ContextException;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.context.spi.Context;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
 /**
  * Web container {@link org.apache.webbeans.spi.ContextsService}
  * implementation.
@@ -107,6 +106,18 @@ public class WebContextsService extends 
         dependentContext.setActive(true);
 
     }
+
+    /**
+     * Removes the ThreadLocals from the ThreadMap to prevent memory leaks.
+     */
+    public static void removeThreadLocals()
+    {
+        requestContext.remove();
+        sessionContext.remove();
+        applicationContext.remove();
+        conversationContext.remove();
+        singletonContext.remove();
+    }
     
     /**
      * Creates a new instance.

Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java?rev=1003138&r1=1003137&r2=1003138&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/lifecycle/WebContainerLifecycle.java
Thu Sep 30 16:20:23 2010
@@ -18,19 +18,9 @@
  */
 package org.apache.webbeans.web.lifecycle;
 
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import javax.el.ELResolver;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.jsp.JspApplicationContext;
-import javax.servlet.jsp.JspFactory;
-
-import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.component.InjectionPointBean;
 import org.apache.webbeans.config.OWBLogConst;
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.corespi.ServiceLoader;
@@ -40,6 +30,16 @@ import org.apache.webbeans.logger.WebBea
 import org.apache.webbeans.spi.ResourceInjectionService;
 import org.apache.webbeans.spi.adaptor.ELAdaptor;
 
+import javax.el.ELResolver;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.jsp.JspApplicationContext;
+import javax.servlet.jsp.JspFactory;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
 /**
  * Manages container lifecycle.
  * 
@@ -157,12 +157,25 @@ public final class WebContainerLifecycle
         }
 
         ContextFactory.cleanUpContextFactory();
+
+        this.cleanupShutdownThreadLocals();
         
         if (logger.wblWillLogInfo())
         {
             logger.info(OWBLogConst.INFO_0002, servletContext != null ? servletContext.getContextPath()
: "null");
         }
     }
+
+    /**
+     * Ensures that all ThreadLocals, which could have been set in this
+     * (shutdown-) Thread, are removed in order to prevent memory leaks.
+     */
+    private void cleanupShutdownThreadLocals()
+    {
+        // TODO maybe there are more to cleanup
+
+        InjectionPointBean.removeThreadLocal();
+    }
     
     /**
      * Returns servelt context otherwise throws exception.



Mime
View raw message