tanyehzheng
tanyehzheng

Reputation: 2221

ThreadLocal memory leak in Glassfish

Will the ThreadLocal cause memory leak in Glassfish server like it leaks in Tomcat? Why? http://wiki.apache.org/tomcat/MemoryLeakProtection

Upvotes: 2

Views: 1838

Answers (2)

Preston
Preston

Reputation: 3271

This problem causes all sorts of issues. I posted about it a while ago

I need help finding my memory leak using MAT

We're manually freeing the objects ourselves. I think I saw in the GF bug lists that this had been fixed in the 3.1x release.

Upvotes: 0

MarianP
MarianP

Reputation: 2759

Yes, it will leak and Glassfish won't even warn you according to this relatively recent Glassfish JIRA issue:

http://java.net/jira/browse/GLASSFISH-14128

What needs to be said however is that the ThreadLocal specific leaking is not a 'bug' in app/web servers per se, but a problem with code in components running in those containers (whether these components are servlets, session beans or whatever).

What app servers/web containers try to do in general is to shield developer from writing a lot of maintenance code and to make him focus on business logic. There needs to be however some understanding on his part of how the application server works (thread pools, classloaders, deploy/undeploy mechanism, ...) so that stuff like this ThreadLocal issue is done properly or avoided. It is not always easy and it can be very tricky. I remember reading about a memory leak issue in Glassfish? related to use of custom log levels.

What Apache Tomcat does is that it has a helper mechanism to warn user/deal with some commonly occurring memory leak issues in user code. But even in the link provided in the question, you may read that not all possible ThreadLocal memory leaks are done automatically using this mechanism.

Glassfish does not seem to have this added functionality yet.

Upvotes: 1

Related Questions