September 13, 2005

Webapps, Reloaded

I had worked recently on a nasty case of Java not unloading web application ClassLoader, which was eventually leading to a dreaded OutOfMemoryError errors. After fixing several application related issues (like having JDBC driver classes jar file in the WEB-INF/lib - don't do this!), problem was reduced to Cocoon's own empty web applications. Thanks to YourKit profiler, I was able to trace it to usage of Excalibur LogKit ContextMap class, which has a ThreadLocal variable. Once I made sure each context.getCurrentContext() is balanced with context.removeCurrentContext(), the problem went away.

While working on this problem, I found great article on many other things which can go wrong when reloading ClassLoader - actually, it's three articles - A day in the life of a memory leak hunter. More on ThreadLocals is written in Tom Hawtin's Fixing ThreadLocal.

Posted by Vadim at September 13, 2005 11:40 PM

The articles are definitely in the "must read" section. And made me realize of potential webapp-reloading memory leak I just introduced in Cocoon, which I fixed quickly :-)

Posted by: Sylvain Wallez at September 14, 2005 6:17 AM