Uploaded image for project: 'OpenWebBeans'
  1. OpenWebBeans
  2. OWB-466

Ensure removal of all ThreadLocal values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0.0-alpha-2
    • 1.0.0
    • None
    • None

    Description

      While running our automated webapp tests with MyFaces CODI and OWB, I always got the following log entries:

      30.09.2010 16:14:14 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
      SCHWERWIEGEND: A web application created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@543c944f]) and a value of type [org.apache.webbeans.inject.impl.InjectionPointImpl] (value [Field Injection Point, field name : postConstructApplicationEvent, Bean Owner : [Name:systemEventBroadcaster,WebBeans Type:MANAGED,API Types:[java.lang.Object,org.apache.myfaces.extensions.cdi.jsf2.impl.listener.system.SystemEventBroadcaster],Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default,javax.inject.Named]]]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
      30.09.2010 16:14:14 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
      SCHWERWIEGEND: A web application created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@552cf9bd]) and a value of type [org.apache.webbeans.context.SessionContext] (value [org.apache.webbeans.context.SessionContext@7bc012fa]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
      30.09.2010 16:14:14 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
      SCHWERWIEGEND: A web application created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@552cf9bd]) and a value of type [org.apache.webbeans.context.SessionContext] (value [org.apache.webbeans.context.SessionContext@7f1e1a8e]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.
      30.09.2010 16:14:14 org.apache.coyote.http11.Http11Protocol destroy

      ..saying that Tomcat's webappclassloader had to remove some ThreadLocal values from the ThreadMap.

      I was able to track the affected ThreadLocal instances down: InstanceBean.local and WebContextsService.sessionContext.

      After digging into the code, I found out that there are many remove() operations on various ThreadLocal instances, but it was not thought that remove() only works for the current Thread. Thus when a ThreadLocal is set during a request it won't be removed when the container stops, because the shutdown-thread is clearly not the same as the request-thread.

      This means the request-ThreadLocal instances have to be removed after every request has ended - in requestDestroyed(ServletRequestEvent event).

      The provided patch adds some remove() calls in requestDestroyed() and also in afterStopApplication(). With this patch none of the above error-logs are shown in any of my test cases. However there might be some other ThreadLocals which should be cleaned up at every request, but this solution currently works for me!

      Attachments

        1. OWB-466.patch
          9 kB
          Jakob Korherr

        Activity

          People

            struberg Mark Struberg
            jakobkorherr Jakob Korherr
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: