Tomcat中的PermGen空间错误 [英] PermGen space Error in tomcat

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

问题描述

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

I am working in Windows Environment. And I am getting this error everytime as 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

我尝试在系统变量中添加 JAVA_OPTS,其值为-Xms1024m -Xmx1024m ,但我仍然得到相同的错误 (java.lang.OutOfMemoryError:PermGen space)一次又一次。任何帮助将不胜感激。我也阅读了stackoverflow中的其他帖子,但它没有成功。

I tried adding JAVA_OPTS with the value as -Xms1024m -Xmx1024m in System Variables, still I am getting the same error (java.lang.OutOfMemoryError: PermGen space) again and again. Any help will be appreciated. I have also read other post in stackoverflow also but it didn't worked out.

推荐答案

PermGen空间是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

然而,我发现最好的方法就是允许卸载类,这样你的PermGen永远不会耗尽:

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

这样的东西过去对我有用。有一件事,在使用这些产品时会有显着的性能折衷,因为每次扫描会对您提出的每个请求或类似的内容提出额外的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中的PermGen空间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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