Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threadlocal memory leak in Threadpool

I am getting threadlocal memory leak errors in Tomcat and I am using ThreadPool, but have no implementation of ThreadLocal in my webapp.

SEVERE: The web application [/myWebApp] created a ThreadLocal with key of type [org.a pache.http.impl.cookie.DateUtils$DateFormatHolder$1] (value [org.apache.http.imp l.cookie.DateUtils$DateFormatHolder$1@4c2849]) and a value of type [java.lang.re f.SoftReference] (value [java.lang.ref.SoftReference@1e67280]) but failed to rem ove it when the web application was stopped. Threads are going to be renewed ove r time to try and avoid a probable memory leak.

What I dont understand is why i am getting threadlocal error although i have not implemented it? I want to get rid of these messages so I searched the web, and in here it is written that in order to clean the threadlocal i need to use:

ThreadLocal.remove()

but I have no implementation of ThreadLocal.. I'll be appreciated if someone show me a way.

like image 358
anvarik Avatar asked Feb 20 '23 15:02

anvarik


2 Answers

Clearly, something is creating that / those ThreadLocal instances. If it is not your code, then it must be some library you are using, or (unlikely) Tomcat itself.

I would start by looking at what might be creating instances of

    org.apache.http.impl.cookie.DateUtils$DateFormatHolder$1

(That's an anonymous class in a nested class in DataUtils, by the way ... so unless something weird is coing on, the creation will be occuring in the DateUtils.java file.)

If examining the source code doesn't help, try debugging the Tomcat instance and setting a breakpoint on the ThreadLocal constructor(s).

like image 177
Stephen C Avatar answered Feb 26 '23 21:02

Stephen C


The problem lies within your third party library. You cannot use thread locals in a thread pooled environment unless you really clean them up after the end of each request.

This article explains the problem: http://blog.maxant.co.uk/pebble/2008/09/23/1222200780000.html

like image 45
jontro Avatar answered Feb 26 '23 23:02

jontro