Bug 49668 - Deeply nested references from ThreadLocal objects are not cleared
Summary: Deeply nested references from ThreadLocal objects are not cleared
Status: RESOLVED DUPLICATE of bug 49159
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.0
Hardware: Sun Solaris
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-29 10:06 UTC by Arjen Knibbe
Modified: 2010-07-30 04:02 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arjen Knibbe 2010-07-29 10:06:10 UTC
Overview
The clearReferencesThreadLocals() method of WebappClassLoader clears two Thread tables from references to the WebappClassLoader. When using axis, the tables can have a HashMap as key, which contains (possibly after many nested HashMaps) a class that was loaded by the WebappClassLoader.

Steps to reproduce
Create a web application that uses the axis 1 SOAP interface. Have the application call ((WebappClassLoader) getClass().getClassLoader()).setClearReferencesThreadLocals(true). Deploy the application in Tomcat. Make a SOAP call to the axis server. Undeploy the web application. Verify in catalina.out that there are warnings about ThreadLocal keys being forcibly unregistered.
Wait an hour, make a memory dump using jmap, and inspect it using jhat.

Actual results
The WebappClassLoader is still present. Its "reference chains from rootset" page shows no references directly from java.lang.ThreadLocal$ThreadLocalMap to an object of a class that is loaded by this WebappClassLoader. It does show references via java.lang.ThreadLocal$ThreadLocalMap and one or more nested HashMaps to the WebappClassLoader:
Static reference from org.apache.catalina.ServerFactory.server (class org.apache.catalina.ServerFactory)
--> org.apache.catalina.core.StandardServer@0xeb400668 (67 bytes) (field services:)
--> [Lorg.apache.catalina.Service;@0xeb4b4178 (12 bytes) (Element 0 of [Lorg.apache.catalina.Service;@0xeb4b4178:)
--> org.apache.catalina.core.StandardService@0xeb4b4188 (62 bytes) (field container:)
--> org.apache.catalina.core.StandardEngine@0xeb4b42c8 (129 bytes) (field thread:)
--> java.lang.Thread@0xeb58b6e0 (104 bytes) (field threadLocals:)
--> java.lang.ThreadLocal$ThreadLocalMap@0xeb58b800 (20 bytes) (field table:)
--> [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;@0xeb58b818 (72 bytes) (Element 8 of [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;@0xeb58b818:)
--> java.lang.ThreadLocal$ThreadLocalMap$Entry@0xeb58b908 (28 bytes) (field value:)
--> java.util.HashMap@0xeb58b928 (40 bytes) (field table:)
--> [Ljava.util.HashMap$Entry;@0xeb58b950 (72 bytes) (Element 0 of [Ljava.util.HashMap$Entry;@0xeb58b950:)
--> java.util.HashMap$Entry@0xeb58bb40 (24 bytes) (field key:)
--> class org.apache.axis.types.Notation (84 bytes) (??:)
--> org.apache.catalina.loader.WebappClassLoader@0xeb5a84a0 (157 bytes)


Expected results
The WebappClassLoader for this application is not present anymore.

Build date & platform
Downloaded Core tar.gz from http://tomcat.apache.org/download-70.cgi
Comment 1 Sylvain Laurent 2010-07-29 14:16:29 UTC
The clearing of thread locals is now disabled by default since it is not thread safe (see BZ 48895).

IMHO, this issue is an enhancement request and would be resolved by implementing BZ 49159.
Comment 2 Arjen Knibbe 2010-07-30 04:02:31 UTC

*** This bug has been marked as a duplicate of bug 49159 ***