In StandardContext method Thread#run is used. This is most probably a mistake, since a few lines below Thread#join is called to wait for the completion of the thread. So we could either remove the join and get rid of the thread by using just a runnable, or start the thread.
Created attachment 27245 [details] use start instead of run to start a thread
I'm wondering why the whole process is run in a Thread in the first place. If the thread is start()ed, when immediately join()ed, and all exceptions are documented not to be expected, it seems like the use of a thread is wasteful. Your patch, while slightly more clear than the original code, does not appear to actually any behavior: the parent thread will still block, except this time the thread is actually launched.
Re Comment #2: http://svn.apache.org/viewvc?view=revision&revision=1044145 Log says: bug 49159: Improve ThreadLocal memory leak clean-up https://issues.apache.org/bugzilla/show_bug.cgi?id=49159 Use a dedicated thread when calling web application code when it is started and stopped (calls to Listeners, Filters, Servlets). Code comment says: // we do it in a dedicated thread for memory leak protection, in // case some webapp code registers some ThreadLocals that they // forget to cleanup Regards, Rainer
Rainer, Aah, I didn't look far enough up in the code to see that comment: thanks for clarifying. Without running Thread.start(), I believe any ThreadLocals registered will be registered to the calling thread, so Felix is right: changing Thread.run to Thread.start is appropriate in this case.
Thanks for the patch. Fixed in 7.0.x and will be included in 7.0.18 onwards.
It seems there used to be call to DedicatedThreadExecutor.executeInOwnThread() but r1087715 changed it to create a new Thread : http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?r1=1087715&r2=1087714&pathrev=1087715