Is there a way to avoid undeployment memory leaks in Tomcat?

前端 未结 2 1396
轻奢々
轻奢々 2020-12-07 15:58

This question is for anyone who\'s ever tested the \"Find leaks\" button in the Tomcat manager and got some results like this:

The following web appli

相关标签:
2条回答
  • 2020-12-07 15:59

    If you want to make sure not to cause leaks you have to do the following:

    • Make sure your web application does not use any java classes that are in the web container shared libraries. If you have any shared libraries, make sure there is no strong references to the objects in those libraries
    • Avoid using static variables, especially on java objects like HashTable, Sets, etc. If you need to, make sure that you call remove to release the objects with the maps, lists...

    Here is also a good article on ThreadLocal and MemoryLeaks - http://blog.arendsen.net/index.php/2005/02/22/threadlocals-and-memory-leaks-revisited/

    0 讨论(0)
  • 2020-12-07 16:16

    Tomcat 7 is supposed to bring improvements in this area. See Features of Apache Tomcat 7, section titled No More Leaks!

    They believe they can now cope with a lot of memory leaks caused by the web applications. Unfortunately, it's still in beta.

    Other than that, I can just say that I've made the same experience and haven't found a solution. Deploying usually requires restarting Tomcat afterwards. I have no idea who the culprit is: my web application, Tomcat, Hibernate, Tapestry or several of them.

    0 讨论(0)
提交回复
热议问题