Memory Leak in Tomcat

memory leaktomcat6

I'm using Tomcat 6.0, JDK 1.6 for a web app.

It's dying frequently requiring manual reboots, and the log file shows this:

Notice: Maximum number of threads (200) created for connector with address null and port 80

Followed by this:

Notice: Waiting for 200 instance(s) to be deallocated

Followed by 200 lines of this:

Severe: The web application [] is still processing a request that has yet to finish. This is very likely to create a memory leak. You can control the time allowed for requests to finish by using the unloadDelay attribute of the standard Context implementation.

Followed by 200 lines of this:

Severe: The web application [] created a ThreadLocal with key of type [net.sourceforge.jtds.jdbc.DateTime$1] (value [net.sourceforge.jtds.jdbc.DateTime$1@1d51620]) and a value of type [java.util.GregorianCalendar] (value [java.util.GregorianCalendar[time=1304607600000,areFieldsSet=true,areAllFieldsSet=false,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Seoul",offset=32400000,dstSavings=0,useDaylight=false,transitions=14,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=4,WEEK_OF_YEAR=19,WEEK_OF_MONTH=1,DAY_OF_MONTH=6,DAY_OF_YEAR=126,DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=1,AM_PM=0,HOUR=0,HOUR_OF_DAY=0,MINUTE=0,SECOND=0,MILLISECOND=0,ZONE_OFFSET=32400000,DST_OFFSET=0]]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

I see this as the GregorianCalendar is leaking, and isn't being gc'ed as usual.

The site does quite often create GregorianCalendar instances, adds a few months or years, formats the resulting Date, and prints the value to the user. However, I would expect that the GregorianCalendar instance is marked for collection as soon as the servlet finishes its request handling method.

What's going on?

Best Answer

It is probably not a memory leak... Your Connector Thread Pool is of size 200 (default) and all 200 connections are in use, this shows you have 200 request that are not terminated... The rest of the logs are because you stop Tomcat with those 200 pending requests... So the question is why are your requests not responding ? You may make a threaddump to see where the requests are blocked...