6 Replies Latest reply on Apr 7, 2006 8:09 PM by rmaucher

    ThreadWithAttributes possible leak

    clebert.suconic

      On this JIRA:

      http://jira.jboss.org/jira/browse/JBAS-3074


      I have done some research on memory leaks on redeployments for WebServices.

      The biggest part of the leakage is already found (look at the JIRA), but there still an issue with ThreadWithAttributes on Tomcat.

      I'm not sure how the Class/ClassLoader got set into ThreadWithAttributes, but is it possible to clear it before the Thread goes back to the pool (to sleep).

      It's going to be hard to create testcases if we don't clear those variables when these threads are in sleep state.


      My idea was to patch ThreadWithAttributes, or make sure that Tomcat is clearing its litter before the Threads goes back to the pool.

      In case we decide by the patch, here is my proposal:

      public class ThreadWithAttributes extends Thread {
       .....
      
       class WraperWeak
       {
       public WrapperWeak(Object obj)
       {
       ref=new WeakReference(obj);
       }
       public Object get()
       {
       return ref.get();
       }
       WeakReference ref;
       }
      
       private HashMap attributes=new HashMap() // Why this needs to be a HashTable if this is a thread-local like structure?
       {
       public void put(Object key, Object value)
       {
       if (value instanceof Class || value instanceof ClassLoader)
       {
       value = new WrapperWeak(value);
       }
       super.put(key,value);
       }
       public void get(Object key)
       {
       value = super.get(key);
       if (value instanceof WrapperWeak)
       {
       return ((WrapperWeak)value).get();
       } else
       {
       return value;
       }
       }
       }
      
       .....
      
      



      Any ideas?