小编典典

如何清除tomcat中的PermGen空间错误

tomcat

我在Windows环境中工作,每次与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

我尝试添加JAVA_OPTS with the value as -Xms1024m -Xmx1024m系统变量,但仍然一次又一次遇到相同的错误
(java.lang.OutOfMemoryError:PermGen空间)

任何帮助将不胜感激。我也阅读了有关Stack Overflow的其他文章,但没有解决。


阅读 383

收藏
2020-06-16

共1个答案

小编典典

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

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

-XX:MaxPermSize=SIZE

但是,我发现永久解决此问题的最佳方法是允许卸载类,以便您的PermGen永远不会用完:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

过去,类似的东西对我来说是神奇的。一件事,在使用这些性能时,需要进行重大的性能折衷,因为对于每个请求或类似的请求,permgen扫描将产生额外的2个请求。您需要权衡利弊。

2020-06-16