Java 在 Tomcat 6 中重复出现“PermGen”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/473011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:04:42  来源:igfitidea点击:

Recurring "PermGen" in Tomcat 6

javamemorytomcat

提问by Berek Bryan

I keep getting a "PermGen" error on my Tomcat 6 server.

我的 Tomcat 6 服务器上不断出现“PermGen”错误。

I know what application is causing the problem, but I am not sure why it is doing so. The application is using MySQL 5 and running on JDK 6.

我知道是什么应用程序导致了问题,但我不确定为什么会这样。该应用程序使用 MySQL 5 并在 JDK 6 上运行。

Are there any tools/suggestions to diagnosis or analyze the underlying issue(s) with the specific application?

是否有任何工具/建议可以诊断或分析特定应用程序的潜在问题?

Thanks

谢谢

采纳答案by kdgregory

The PermGen is used to store class definitions and the interned string pool. Your code could be filling it (if it calls intern needlessly), but more likely is that the default is undersized for your application.

PermGen 用于存储类定义和内部字符串池。您的代码可能正在填充它(如果它不必要地调用了 intern),但更有可能是您的应用程序的默认值过小。

This is because Tomcat will load new classes every time you deploy a WAR -- or, if you are working in a development environment, every time you edit a JSP. Those should eventually get cleaned up, but in an active development environment you can have periods where there are both old and new instances loaded. Or, if you're in a production environment and have a large web-app, you might simply need more space.

这是因为每次部署 WAR 时 Tomcat 都会加载新类 —— 或者,如果您在开发环境中工作,则每次编辑 JSP 时都会加载新类。这些最终应该会得到清理,但在活跃的开发环境中,您可能会遇到同时加载新旧实例的时期。或者,如果您在生产环境中并且拥有大型 Web 应用程序,您可能只需要更多空间。

To set the permgen size, use -XX:MaxPermSize=SIZE

要设置永久大小,请使用 -XX:MaxPermSize=SIZE

The following links may be helpful: tuning GC(this is the 1.5 edition), GC FAQ(1.4.2 edition), Hotspot VM options(I believe this is 1.6)

以下链接可能会有所帮助:调优 GC(这是 1.5 版)、GC FAQ(1.4.2 版)、Hotspot VM 选项(我相信这是 1.6)

回答by kdgregory

I think you might have many JSPs in your application. There is a known issue in tomcat where restarting a deployed application with many JSPs causes PermGen issues because tomcat recompiles and reloads all these classes again. Increasing the size as mentioned in the previous post should help.

我认为您的应用程序中可能有很多 JSP。在 tomcat 中存在一个已知问题,即重新启动具有许多 JSP 的已部署应用程序会导致 PermGen 问题,因为 tomcat 会重新编译并重新加载所有这些类。增加上一篇文章中提到的大小应该会有所帮助。

回答by opyate

Try the following JVM switches:

尝试以下 JVM 开关:

-XX:+UseConcMarkSweepGC
-XX:+CMSPermGenSweepingEnabled
-XX:+CMSClassUnloadingEnabled

Upping the permgen space with -XX:MaxPermSizejust delays the problem.

增加 permgen 空间-XX:MaxPermSize只会延迟问题。

Please see this comment: How to deal with “java.lang.OutOfMemoryError: PermGen space” error

请参阅此评论: 如何处理“java.lang.OutOfMemoryError: PermGen space”错误

That indirectly pointed me to these two posts: problem, solution

这间接地将我指向了这两篇文章:问题解决方案

回答by Theresa Forster

I have seen lots of permgen errors when tomcat is reloaded after a code change when using hibernate and spring, I think its due to the logger/ehcache instances not being shut down properly.

在使用 hibernate 和 spring 时更改代码后重新加载 tomcat 时,我看到了很多 permgen 错误,我认为这是由于 logger/ehcache 实例没有正确关闭。

回答by Fun With Puzzles

I agree that increasing the permgen space with -XX:MaxPermSize just delays the problem. I tried increasing the permgen and after that I started getting the same error after I sent more number of requests to my server. Additional flags like -XX:+CMSClassUnloadingEnabled is suggested even though it will decrease the performance little bit.

我同意使用 -XX:MaxPermSize 增加 permgen 空间只会延迟问题。我尝试增加 permgen,然后在向服务器发送更多请求后开始收到相同的错误。建议使用像 -XX:+CMSClassUnloadingEnabled 这样的附加标志,即使它会稍微降低性能。

回答by Ganesh Tripathi

try this : IN Linux Machines

试试这个:在 Linux 机器上

export JAVA_OPTS="-XX:PermSize=128m"

export JAVA_OPTS="-XX:PermSize=128m"