1

I am currently using tomcat7 . my web application has caused a Timer memory leak on stop . the log is :

   SEVERE: A web application appears to have started a TimerThread     
   named [Timer-5] via the java.util.Timer API but has failed to stop it. 
   To prevent a memory leak, the timer (and hence the associated thread) 
   has been forcibly cancelled.   

I am not using java.util.Timer in my web-app.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Amir Taghvayi
  • 23
  • 1
  • 4

3 Answers3

2

This does not necessarily indicate that your code is using java.util.Timer (which is by the way an extremely bad idea in a Java EE webapp, for the reasons mentioned here). This Timer can also be included as part of any of the libraries supplied in your webapp's /WEB-INF/lib folder. Apparently some library has auto-registered a ServletContextListener or ServletContainerInitializer on webapp's startup wherein the Timer is been created.

You need to investigate which library it is and then fix/remove it accordingly. Extract the JARs to check the enclosed code, or remove them one by one. Once the culprit is found, I'd surely report to the library's maintainers that using Timer is absolutely not recommended in a Java EE webapp and that they have to fix it.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • @Balusc How can you tell that some library has auto-registered a ServletContextListener or ServletContainerInitializer? – Pidster May 24 '12 at 20:00
  • @Pidster: By checking for any `*.tld`, `/META-INF/services/*`, `web-fragment.xml` files in the JAR. Or by reading the JAR file vendor's documentation. – BalusC May 24 '12 at 20:01
  • That's not what I meant. How can *you* tell that this is the case with the OPs situation - there's no evidence from the limited information above that this is the case. – Pidster May 28 '12 at 12:33
  • @Pidster: OP literally said "I am not using `java.util.Timer` in my web-app". So then it's either the servletcontainer itself or any of the libraries deployed along the webapp. Seems logical, isn't it? – BalusC May 28 '12 at 12:34
  • @BalusC I agree that a library may have started it. A JRE class may have also started it. I disagree with your statement "Apparently some library has auto-registered a ServletContextListener or ServletContainerInitializer". – Pidster May 30 '12 at 09:48
  • @Pidster: Your choice. It's just theoretically possible if a ServletContextListener or ServletContainerInitializer has in turn started the Timer. – BalusC May 30 '12 at 12:28
0

This one I am not so certain of. There appears to be an RMI timeout timer, but all of that is part of Tomcat, so it should not be a leak

Amir Taghvayi
  • 23
  • 1
  • 4
0

In tomcat wiki there is an explanation (kind of) and a link to this bug in commons-pool.

The timer stop is optional in tomcat >6.0.27

ssedano
  • 8,322
  • 9
  • 60
  • 98