我发现这是 Tomcat 上的一个众所周知的问题,所以我试图在我的服务器上解决它。
在我的 Tomcat 上部署/取消部署 war 文件我经常收到检查内存泄漏的警报:
The following web applications were stopped (reloaded, undeployed), but their
classes from previous runs are still loaded in memory, thus causing a memory
leak (use a profiler to confirm):
/GEKKO
/GEKKO
/GEKKO
/LinkPlatform
这个答案 https://stackoverflow.com/a/4565522/1061499 建议:
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
这是什么意思?我在我的 Eclipse 项目中使用 Maven,所有依赖项都会自动加载。但是我必须在项目构建路径(服务器运行时)中手动添加 Tomcat 库。这是问题吗? Tomcat jars 是“共享库”吗?
最佳答案
Tomcat 在运行时提供的 Jar 应该被限定为 provided
如果您需要它们进行编译但希望 Tomcat 容器在运行时提供它们,例如
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
(版本只是我扔在那里的东西......使用任何合适的东西)。
关于java - Tomcat 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26635721/