如何清除tomcat中的永久代空间错误 [英] How to clear PermGen space Error in tomcat

查看:23
本文介绍了如何清除tomcat中的永久代空间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 环境中工作,每次使用 tomcat 时都会收到此错误-

I am working in a Windows Environment, and I am getting this error every time I am working with tomcat-

Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@4ae53a99
2012-04-30 17:30:37.719 INFO net.spy.memcached.MemcachedConnection:  Reconnecting due to failure to connect to {QA sa=localhost/127.0.0.1:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0}
java.net.ConnectException: Connection refused: no further information
Apr 30, 2012 5:30:37 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
Exception in thread "Memcached IO over {MemcachedConnection to localhost/127.0.0.1:11211}" java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process
SEVERE: Error processing request
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process
SEVERE: Error processing request
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:38 PM org.apache.coyote.http11.Http11Processor process
SEVERE: Error processing request
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:41 PM org.apache.catalina.connector.CoyoteAdapter service
SEVERE: An exception or error occurred in the container during the request processing
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:43 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.action]
java.lang.OutOfMemoryError: PermGen space
Apr 30, 2012 5:30:42 PM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/error.action]
java.lang.OutOfMemoryError: PermGen space
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space

我尝试在系统变量中添加值为 -Xms1024m -Xmx1024m 的 JAVA_OPTS,但我仍然遇到相同的错误 (java.lang.OutOfMemoryError: PermGen space)一次又一次.

I tried adding JAVA_OPTS with the value as -Xms1024m -Xmx1024m in System Variables, but I am stillgetting the same error (java.lang.OutOfMemoryError: PermGen space) again and again.

任何帮助将不胜感激.我还阅读了 Stack Overflow 上的其他帖子,但没有成功.

Any help will be appreciated. I have also read other posts on Stack Overflow also but it didn't work out.

推荐答案

永久代空间是 Tomcat 用来存储类定义(仅定义,无实例化)和已被实习的字符串池的空间.根据经验,PermGen 空间问题往往在开发环境中经常发生,因为 Tomcat 每次部署 WAR 或执行 jspc(当您编辑 jsp 文件时)都必须加载新类.就我个人而言,当我在进行开发测试时,我倾向于经常部署和重新部署战争,所以我知道我迟早会用完(主要是因为 Java 的 GC 周期仍然有点废话,所以如果你快速和频繁地重新部署战争足够了,空间填满的速度超出了他们的管理能力).

The PermGen space is what Tomcat uses to store class definitions (definitions only, no instantiations) and string pools that have been interned. From experience, the PermGen space issues tend to happen frequently in dev environments really since Tomcat has to load new classes every time it deploys a WAR or does a jspc (when you edit a jsp file). Personally, I tend to deploy and redeploy wars a lot when I’m in dev testing so I know I’m bound to run out sooner or later (primarily because Java’s GC cycles are still kinda crap so if you redeploy your wars quickly and frequently enough, the space fills up faster than they can manage).

理论上,这在生产环境中应该不是问题,因为您(希望)不会在 10 分钟内更改代码库.如果它仍然发生,那只是意味着您的代码库(和相应的库依赖项)对于默认内存分配来说太大了,您只需要处理堆栈和堆分配.我认为标准是这样的:

This should theoretically be less of an issue in production environments since you (hopefully) don’t change the codebase on a 10 minute basis. If it still occurs, that just means your codebase (and corresponding library dependencies) are too large for the default memory allocation and you’ll just need to mess around with stack and heap allocation. I think the standards are stuff like:

-XX:MaxPermSize=SIZE

然而,我发现解决这个问题的最好方法是允许卸载类,这样您的永久代就不会耗尽:

I’ve found however the best way to take care of that for good is to allow classes to be unloaded so your PermGen never runs out:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

过去这样的事情对我来说很神奇.有一件事,使用这些会带来显着的性能折衷,因为 permgen 扫描会为您提出的每个请求或类似的东西产生额外的 2 个请求.您需要在使用与权衡之间取得平衡.

Stuff like that worked magic for me in the past. One thing tho, there’s a significant performance tradeoff in using those, since permgen sweeps will make like an extra 2 requests for every request you make or something along those lines. You’ll need to balance your use with the tradeoffs.

这篇关于如何清除tomcat中的永久代空间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆