Is this very likely to create a memory leak in Tomcat?

前端 未结 5 2167
日久生厌
日久生厌 2020-11-29 01:29

I configured tomcat to work with a different external open source.

However, after the tomcat is running for a few minutes I get:

SEVERE: The w

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 01:32

    This problem appears when we are using any third party solution, without using the handlers for the cleanup activitiy. For me this was happening for EhCache. We were using EhCache in our project for caching. And often we used to see following error in the logs

     SEVERE: The web application [/products] appears to have started a thread named [products_default_cache_configuration] but has failed to stop it. This is very likely to create a memory leak.
    Aug 07, 2017 11:08:36 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
    SEVERE: The web application [/products] appears to have started a thread named [Statistics Thread-products_default_cache_configuration-1] but has failed to stop it. This is very likely to create a memory leak.
    

    And we often noticed tomcat failing for OutOfMemory error during development where we used to do backend changes and deploy the application multiple times for reflecting our changes.

    This is the fix we did

    
      
         net.sf.ehcache.constructs.web.ShutdownListener
      
    
    

    So point I am trying to make is check the documentation of the third party libraries which you are using. They should be providing some mechanisms to clean up the threads during shutdown. Which you need to use in your application. No need to re-invent the wheel unless its not provided by them. The worst case is to provide your own implementation.

    Reference for EHCache Shutdown http://www.ehcache.org/documentation/2.8/operations/shutdown.html

提交回复
热议问题