<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:34 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[JAVA-130] Memory Leaks with ThreadLocals in Tomcat</title>
                <link>https://jira.mongodb.org/browse/JAVA-130</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;When running mongo 2.0 in a tomcat environment I can see the following logs in the catalina.out, and the tomcat web server can&apos;t be stopped any more without killing it, it seems that there&apos;s a non-deamon thread still hanging.&lt;/p&gt;

&lt;p&gt;SEVERE: A web application created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$1@d5ba1ef&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector.MyPort&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$MyPort@7ae458c2&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.&lt;br/&gt;
Jul 8, 2010 7:28:23 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap&lt;br/&gt;
SEVERE: A web application created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.OutMessage$1@257f6796&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.OutMessage&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.OutMessage@4f69bc15&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.&lt;br/&gt;
Jul 8, 2010 7:28:23 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap&lt;br/&gt;
SEVERE: A web application created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.Response$1@26bb2f6e&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;org.bson.BSONDecoder&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;org.bson.BSONDecoder@4b26f29f&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.&lt;/p&gt;</description>
                <environment>Fedora, Tomcat</environment>
        <key id="12388">JAVA-130</key>
            <summary>Memory Leaks with ThreadLocals in Tomcat</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="klu2">Klaus Lehner</reporter>
                        <labels>
                    </labels>
                <created>Fri, 9 Jul 2010 03:39:24 +0000</created>
                <updated>Tue, 9 Nov 2010 07:55:03 +0000</updated>
                            <resolved>Thu, 30 Sep 2010 20:57:13 +0000</resolved>
                                    <version>2.0</version>
                                    <fixVersion>2.2</fixVersion>
                                                        <votes>4</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="20163" author="klu2" created="Tue, 9 Nov 2010 07:55:03 +0000"  >&lt;p&gt;ah sorry - forgot to call close() as mentioned by eliot; will give that a try&lt;/p&gt;</comment>
                            <comment id="20162" author="eliot" created="Tue, 9 Nov 2010 07:52:28 +0000"  >&lt;p&gt;Can you create a new case with the full log and steps to reproduce exactly?&lt;/p&gt;</comment>
                            <comment id="20160" author="klu2" created="Tue, 9 Nov 2010 07:50:08 +0000"  >&lt;p&gt;This is still the case, even with 2.3.&lt;/p&gt;

&lt;p&gt;I still have errors like that in my catalina.out and tomcat can&apos;t be stopped without killing it. Please reopen that task.&lt;/p&gt;

&lt;p&gt;SEVERE: A web application created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$1@4b6eb12&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector.MyPort&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$MyPort@6fe23ecd&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.&lt;/p&gt;</comment>
                            <comment id="19064" author="eliot" created="Mon, 11 Oct 2010 12:02:19 +0000"  >&lt;p&gt;The 2 in org.bson should never be using by normal operations, and accoring to tomcat docs, it seems the other should be.&lt;br/&gt;
If you see issues in an app - please open a new ticket with the exact errors&lt;/p&gt;</comment>
                            <comment id="19063" author="daspilker" created="Mon, 11 Oct 2010 11:56:12 +0000"  >&lt;p&gt;I tried the 2.2 driver today. Unfortunately this issue seems not to be fixed. I still count 3 thread locals (2 in org.bson.BSON and 1 in com.mongodb.DBTCPConnector). I do not see why these should get GC&apos;ed when Mongo.close() is called, since the contents of the thread locals will still be referenced from each thread which used these classes. It will get GC&apos;ed when the threads die, but in a shared environment like servlet containers where threads are pooled and reused this is not going to happen.&lt;/p&gt;</comment>
                            <comment id="19038" author="robertstewart" created="Sat, 9 Oct 2010 07:09:02 +0000"  >&lt;p&gt;At first, I was still seeing one message being logged at SEVERE level. Tomcat, at least in version 6.0.24, seemed to be taking things into its own hands, though.&lt;/p&gt;

&lt;p&gt;Oct 8, 2010 11:08:19 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap&lt;br/&gt;
SEVERE: A web application created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$1@2f4f069b&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector.MyPort&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$MyPort@6d3ac260&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.&lt;/p&gt;

&lt;p&gt;This happens when I undeploy a webapp on Tomcat 6.0.24. The last sentence in the message is different than in previous comments posted on this issue. I think this is due to changes in more recent versions of Tomcat 6.0.x.&lt;/p&gt;

&lt;p&gt;In my webapp, I&apos;m using my log4mongo-java appender for Log4J to log events to MongoDB. I&apos;ve registered a ServletContextListener in my webapp that is called when the context is destroyed (e.g., when undeploying a webapp or shutting down Tomcat). In the callback, I Log4J&apos;s LogManager.close(), which eventually calls the close method on my appender, which finally calls Mongo.close().&lt;/p&gt;

&lt;p&gt;After I patched mongo-java-driver with the fix I identified in &lt;a href=&quot;http://jira.mongodb.org/browse/JAVA-180&quot; class=&quot;external-link&quot; rel=&quot;nofollow&quot;&gt;http://jira.mongodb.org/browse/JAVA-180&lt;/a&gt; (an NPE was preventing final clean up from occurring), the ThreadLocal was cleaned up and no messages were logged at SEVERE level.&lt;/p&gt;

&lt;p&gt;So, the 2.2 driver fixes the problems I was seeing with 2.1.&lt;/p&gt;</comment>
                            <comment id="18719" author="eliot" created="Thu, 30 Sep 2010 20:57:13 +0000"  >&lt;p&gt;If you call Mongo.close() on application quit, everything should be cleaned up now.&lt;br/&gt;
Removed 2 main ThreadLocal&lt;br/&gt;
The last one should be cleaned with Mongo.close() when Mongo is gc&apos;ed&lt;/p&gt;</comment>
                            <comment id="18718" author="auto" created="Thu, 30 Sep 2010 20:55:00 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: don&apos;t put OutMessage in ThreadLocal.&lt;br/&gt;
store buffers in Mongo not ThreadLocal&lt;br/&gt;
&lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-130&quot; title=&quot;Memory Leaks with ThreadLocals in Tomcat&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-130&quot;&gt;&lt;del&gt;JAVA-130&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo-java-driver/commit/396cd5796cb1e627787e62f53e460465a95ac0b0&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo-java-driver/commit/396cd5796cb1e627787e62f53e460465a95ac0b0&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="18717" author="auto" created="Thu, 30 Sep 2010 20:54:57 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: doing our own UTF-8 Encoding so we can avoid extra buffers.  this makes BSONEncoder lightweight&lt;br/&gt;
prep for &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-130&quot; title=&quot;Memory Leaks with ThreadLocals in Tomcat&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-130&quot;&gt;&lt;del&gt;JAVA-130&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo-java-driver/commit/cde408cac4abc0322d1c67f9f57e5e4e19413cf9&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo-java-driver/commit/cde408cac4abc0322d1c67f9f57e5e4e19413cf9&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="18712" author="auto" created="Thu, 30 Sep 2010 18:08:50 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: remove 1 ThreadLocal by putting BSONDecoder in DBPort &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-130&quot; title=&quot;Memory Leaks with ThreadLocals in Tomcat&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-130&quot;&gt;&lt;del&gt;JAVA-130&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
From hans&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo-java-driver/commit/0cc187f55680856929925b3b43c68b1cb4042d0f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo-java-driver/commit/0cc187f55680856929925b3b43c68b1cb4042d0f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="18419" author="hmeiser" created="Wed, 22 Sep 2010 09:50:32 +0000"  >&lt;p&gt;Patch to move BSONDecoder into DBPort and remove threadlocal in Response. BSONDecoder is now per connection.&lt;br/&gt;
DBPort is pooled and so BSONDecoder is also pooled.&lt;/p&gt;</comment>
                            <comment id="17611" author="eliot" created="Tue, 31 Aug 2010 14:19:50 +0000"  >&lt;p&gt;Still trying to figure out exactly what the bug or standard fix is.&lt;/p&gt;</comment>
                            <comment id="17542" author="klu2" created="Mon, 30 Aug 2010 12:58:21 +0000"  >&lt;p&gt;any forecast when this will be fixed?&lt;/p&gt;</comment>
                            <comment id="17210" author="mdelaurentis" created="Mon, 23 Aug 2010 20:20:26 +0000"  >&lt;p&gt;I&apos;m seeing this issue also, using the 2.0 version of the driver, with tomcat 6.0.29.  I get these messages:&lt;/p&gt;

&lt;p&gt;SEVERE: The web application &lt;span class=&quot;error&quot;&gt;&amp;#91;/vbz2-0.1&amp;#93;&lt;/span&gt; appears to have started a thread named &lt;span class=&quot;error&quot;&gt;&amp;#91;ObjectId-TimeFixer&amp;#93;&lt;/span&gt; but has failed to stop it. This is very likely to create a memory leak.&lt;br/&gt;
SEVERE: The web application &lt;span class=&quot;error&quot;&gt;&amp;#91;/vbz2-0.1&amp;#93;&lt;/span&gt; created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.OutMessage$1@a12487&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.OutMessage&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.OutMessage@165381c&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.&lt;br/&gt;
SEVERE: The web application &lt;span class=&quot;error&quot;&gt;&amp;#91;/vbz2-0.1&amp;#93;&lt;/span&gt; created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$1@46e524&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector.MyPort&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.DBTCPConnector$MyPort@6dc8af&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.&lt;br/&gt;
SEVERE: The web application &lt;span class=&quot;error&quot;&gt;&amp;#91;/vbz2-0.1&amp;#93;&lt;/span&gt; created a ThreadLocal with key of type &lt;span class=&quot;error&quot;&gt;&amp;#91;null&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;com.mongodb.Response$1@f3a7d5&amp;#93;&lt;/span&gt;) and a value of type &lt;span class=&quot;error&quot;&gt;&amp;#91;org.bson.BSONDecoder&amp;#93;&lt;/span&gt; (value &lt;span class=&quot;error&quot;&gt;&amp;#91;org.bson.BSONDecoder@8fc7ce&amp;#93;&lt;/span&gt;) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.&lt;/p&gt;</comment>
                            <comment id="16455" author="daspilker" created="Wed, 4 Aug 2010 06:31:24 +0000"  >&lt;p&gt;This is not a Tomcat specific problem. It applies to all JEE application servers and OSGI environments.&lt;/p&gt;

&lt;p&gt;I found this link which describes memory leaks in JEE environments: &lt;a href=&quot;http://www.java-community.de/archives/140-Memory-leaks-et-alii.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.java-community.de/archives/140-Memory-leaks-et-alii.html&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="16335" author="eliot" created="Sat, 31 Jul 2010 14:30:15 +0000"  >&lt;p&gt;Removing the thread locals is not an option.&lt;br/&gt;
In my simple testing its 20% slower - and when gc becomes heavy in apps, it&apos;ll be even worse.&lt;/p&gt;

&lt;p&gt;Can anyone point to tomcat documentation on what they&apos;re thinking/expecting?&lt;/p&gt;</comment>
                            <comment id="16310" author="daspilker" created="Fri, 30 Jul 2010 16:10:20 +0000"  >&lt;p&gt;I created two more patches to get rid of two of the ThreadLocals: &lt;a href=&quot;http://github.com/daspilker/mongo-java-driver/commit/c72945ca0518265b2db6dad92e1c63a09331cdcf&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/daspilker/mongo-java-driver/commit/c72945ca0518265b2db6dad92e1c63a09331cdcf&lt;/a&gt; and &lt;a href=&quot;http://github.com/daspilker/mongo-java-driver/commit/bf47166013d03e5d798318eb9744b8c6586e70ff&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/daspilker/mongo-java-driver/commit/bf47166013d03e5d798318eb9744b8c6586e70ff&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I understand the code these ThreadLocals avoid object creation for OutMessage and BSONDecoder objects. But these objects are cheap to create. So it should not decrease throughput when not caching instances of these objects.&lt;/p&gt;</comment>
                            <comment id="16305" author="daspilker" created="Fri, 30 Jul 2010 14:25:44 +0000"  >&lt;p&gt;Cool, I&apos;m currently trying the same. I also noted a decrease in throughput, but I can live with that.&lt;/p&gt;</comment>
                            <comment id="16304" author="eliot" created="Fri, 30 Jul 2010 14:16:00 +0000"  >&lt;p&gt;I got rid of the ObejctId Thread.&lt;br/&gt;
its only a little slower to just call currentTimeMillis() every time&lt;br/&gt;
i can generate 20M object ids per second on by box, down from 30M or so&lt;/p&gt;</comment>
                            <comment id="16092" author="eliot" created="Fri, 23 Jul 2010 15:08:38 +0000"  >&lt;p&gt;I don&apos;t these are serious.&lt;br/&gt;
At most its a slight memory leak.&lt;/p&gt;

&lt;p&gt;I still don&apos;t understand what tomcat is thinking - really doesn&apos;t make much sense to me at this point...&lt;/p&gt;</comment>
                            <comment id="16091" author="mattupstate" created="Fri, 23 Jul 2010 15:06:41 +0000"  >&lt;p&gt;Would just like to say that this happens on Windows as well. Its quite disconcerting to see these &quot;severe&quot; messages from Tomcat when reloading or stopping the webapp. Do we need to be concerned about them? It sounds like there is some significant differences in understanding amongst the comments on this issue.&lt;/p&gt;

&lt;p&gt;In addition to the ThreadLocal messages I also get this message just before them:&lt;/p&gt;

&lt;p&gt;SEVERE: The web application &lt;span class=&quot;error&quot;&gt;&amp;#91;/compositor&amp;#93;&lt;/span&gt; appears to have started a thread named &lt;span class=&quot;error&quot;&gt;&amp;#91;ObjectId-TimeFixer&amp;#93;&lt;/span&gt; but has failed to stop it. This is very likely to create a memory leak.&lt;br/&gt;
Jul 23, 2010 10:43:48 AM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap&lt;/p&gt;</comment>
                            <comment id="16088" author="eliot" created="Fri, 23 Jul 2010 14:30:51 +0000"  >&lt;p&gt;That change is bad because if you have multiple Mongo instances closing one will stop the thread which is very bad.&lt;br/&gt;
I&apos;ll see if I can do something next week.&lt;/p&gt;</comment>
                            <comment id="16087" author="daspilker" created="Fri, 23 Jul 2010 14:27:53 +0000"  >&lt;p&gt;There are shutdown hooks defined by the Servlet API, but I think it is not a good practice for a database driver to register any hooks with a Servlet engine. The driver shut provide some methods to dispose all resources used by the driver. The web application is responsible for calling such methods when it is been undeployed. E.g. the web app needs to class mongo.close() for all mongo objects which have been created by the web application. When there are further resources, like threads which are shared by several mongo objects, the driver can expose more methods which the application must call to dispose these resources.&lt;/p&gt;

&lt;p&gt;I forked the Java driver on GitHub and added a method to stop the thread which is used by ObjectId. Please have a look at &lt;a href=&quot;http://github.com/daspilker/mongo-java-driver/commit/664383806941ad148f25fd19b428139248f2f200&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/daspilker/mongo-java-driver/commit/664383806941ad148f25fd19b428139248f2f200&lt;/a&gt;. My application calls mongo.close() and ObjectId.stopTimer() when it is being undeployed. This resolves the problem that the ObjectId thread keeps on running when the application is undeployed.&lt;/p&gt;</comment>
                            <comment id="16071" author="eliot" created="Thu, 22 Jul 2010 21:15:23 +0000"  >&lt;p&gt;Do you know if a shutdown hook will be executed for each container?&lt;br/&gt;
If so I can easily add a shutdown hook&lt;/p&gt;</comment>
                            <comment id="16070" author="daspilker" created="Thu, 22 Jul 2010 21:12:43 +0000"  >&lt;p&gt;Every webapp is loaded with it&apos;s own class loader. So when you have two webapps running in one Tomcat instance all classes are loaded and initialized twice. This means that the thread started in the static initializer in ObjectId is started twice, once for each webapp.&lt;/p&gt;

&lt;p&gt;I think this behavior is mandated by the Servlet specification and is true for every Servlet container, not only for Tomcat.&lt;/p&gt;

&lt;p&gt;Disposing everything on Mongo.close() may not be a good idea, when you have multiple mongo connections in one webapp. But there should be a way to clean things up after the last connection has been closed.&lt;/p&gt;</comment>
                            <comment id="16068" author="eliot" created="Thu, 22 Jul 2010 20:52:30 +0000"  >&lt;p&gt;Its a little weird though because in a normal open - you may have multiple Mongo objects, but a thread may use many.&lt;/p&gt;

&lt;p&gt;So having Mongo.close() clear thread locals seems like a really bad idea...&lt;/p&gt;

&lt;p&gt;Does tomcat guarantee that a single Thread only is used by a single app?&lt;/p&gt;
</comment>
                            <comment id="16067" author="daspilker" created="Thu, 22 Jul 2010 20:47:28 +0000"  >&lt;p&gt;Tomcat executes the shutdown hooks for servlet etc. This is where we are calling Mongo.close(). I would expect Mongo.close() to dispose all resources used by the driver, including clearing ThreadLocals and stopping any threads.&lt;/p&gt;</comment>
                            <comment id="16050" author="eliot" created="Thu, 22 Jul 2010 16:54:45 +0000"  >&lt;p&gt;What is the hook tomcat expects to use to clean things up?&lt;/p&gt;</comment>
                            <comment id="16049" author="daspilker" created="Thu, 22 Jul 2010 16:52:55 +0000"  >&lt;p&gt;We are running the MongoDB Java driver 2.0 in a webapp in Tomcat 7.0.0 beta and we are seeing the same messages as Klaus did.&lt;/p&gt;

&lt;p&gt;Additionally there is a thread which is marked as daemon, but not stopped when the webapp is undeloyed:&lt;/p&gt;

&lt;p&gt;22.07.2010 18:47:25 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads&lt;br/&gt;
SEVERE: The web application [] appears to have started a thread named &lt;span class=&quot;error&quot;&gt;&amp;#91;ObjectId-TimeFixer&amp;#93;&lt;/span&gt; but has failed to stop it. This is very likely to create a memory leak. &lt;/p&gt;</comment>
                            <comment id="15974" author="eliot" created="Tue, 20 Jul 2010 15:19:33 +0000"  >&lt;p&gt;Can you get a thread name for that?&lt;br/&gt;
There shouldn&apos;t be...&lt;/p&gt;</comment>
                            <comment id="15971" author="klu2" created="Tue, 20 Jul 2010 15:14:51 +0000"  >&lt;p&gt;It also seems that there is a non-daemon thread that is not terminating when tomcat is stopped.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="10462" name="threadlocal1.patch" size="2015" author="hmeiser" created="Wed, 22 Sep 2010 09:50:32 +0000"/>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrhd2f:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14917</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>