[ 
http://issues.apache.org/jira/browse/HIVEMIND-161?page=comments#action_12360105 
] 

Howard M. Lewis Ship commented on HIVEMIND-161:
-----------------------------------------------

I think you have definately uncovered a minor design flaw here.

The hivemind.ThreadEventNotifier service was designed so that service 
implementations, or other objects, could register and unregister at will.

If you check the code, the majority of objects that register with the notifier 
will unregister themselves inside threadDidCleanup().

However, you are absolutely correct that there's nothing to discard a thread's 
event locals after the thread is done or the registry shutdown.  This is one of 
those situations where an application server can provide a level of lifecycle 
support that a framework, operating generically as HiveMind does, can not.  
Thus the need for Registry methods setupThread() and cleanupThread().  In fact, 
the HiveMind servlet exists primarily to invoke those two methods.

So I believe we do need a change in design direction, to discard all 
ThreadLocals at the end of the current request. This includes the list of 
ThreadCleanupListener, but any others we're using within the code.

One of the nice things about HiveMind is that, once we properly handle this, 
user code won't be suspectible to the same problem.
 
A careful review of this code, as well as any other code that makes use of a 
ThreadLocal is needed.

I'll need to look at the unit test, to see if the changes you've mentioned are 
correct; I suspect they are.  Great find!  

I suspect there will be a HiveMind 1.1.1, and a Tapestry 4.0.1 to make use of 
it.

> ThreadLocal object is never removed in ThreadEventNotifierImpl and holds the 
> classloader
> ----------------------------------------------------------------------------------------
>
>          Key: HIVEMIND-161
>          URL: http://issues.apache.org/jira/browse/HIVEMIND-161
>      Project: HiveMind
>         Type: Bug
>   Components: framework
>     Versions: 1.1
>  Environment: Tomcat 5.5.12, J2SE 1.6 Mustang build 62, Win XP SP2
>     Reporter: Kyrill Alyoshin
>     Priority: Critical
>  Attachments: hivemind-threadlocals.pdf
>
> The following prevents the web application classloader from being garbage 
> collected on hot redeploys of web applications. 
> Please note that the issue is present on J2SE 1.5 as well. I use 1.6 only 
> because it has far better support for JVMTI and as such the issue was easy to 
> discover with YourKit profiler. Here it is:
> 1. org.apache.hivemind.service.impl.ThreadEventNotifierImpl puts 
> EventListenerList ("list" variable) on its private ThreadLocal "_storage" 
> variable in addThreadCleanupListener method.
> 2. No where in that class does the actual list gets removed from ThreadLocal.
> Thus, the WebappClassLoader cannot be garbage collected because one of the 
> object that it loaded (i.e. EventListenerList) is strongly referenced by live 
> threads in the container, which leads to huge memory leaks on hot-redeploys.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to