Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
Java-SCA-1.6
-
None
Description
On Tomcat 7, when a Tuscany webapp is stopped, the following message is displayed:
SEVERE: The web application [/sample-calculator-webapp] created a ThreadLocal with key of type [null] (value
[org.apache.tuscany.sca.core.invocation.ThreadMessageContext$1@1b071c0]) and a value of type
[org.apache.tuscany.sca.core.invocation.MessageImpl] (value [org.apache.tuscany.sca.core.invocation.MessageImpl@fbf51d])
but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
This happens because Tuscany adds a thread-local ThreadMessageContext object to every invocation thread when starting a request invocation and doesn't remove this object when the request is complete.
There is code in WebAppServletHost.destroy() that attempts to remove this context information when the webapp is stopped. This usually doesn't succeed in removing the context information because the ThreadLocal.remove() method only removes context information from the current thread and not from other threads. There's no Java API for removing this information from other threads.
The only way to remove this information is to track the completion of each request invocation and remove the context information from the current thread when the request has been completed. The context information will be recreated for the next request on the thread. This is very easy to implement by adding a few lines of code to the ThreadMessageContext class.