java heap space, PermGen space 错误

使用myeclipse启动tomcat 报java heap space ,PermGen space 错误,分别为 heap内存不足,PermGen内存不足

需加大 tomcat启动项参数 Xmx 和 XX:MaxPermSize

PermGen是指内存的永久保存区域,它用于存放class和 method 对象,以及String 对象

(sun原文:permanent generation is the area of the heap where class and method objects are stored. If an application loads a very large number of classes, then the size of the permanent generation might need to be increased using the -XX:MaxPermSize option.

Interned java.lang.String objects are also stored in the permanent generation. The java.lang.String class maintains a pool of strings. When the intern method is invoked, the method checks the pool to see if an equal string is already in the pool. If there is, then the intern method returns it; otherwise it adds the string to the pool. In more precise terms, the java.lang.String.intern method is used to obtain the canonical representation of the string; the result is a reference to the same class instance that would be returned if that string appeared as a literal. If an application interns a huge number of strings, the permanent generation might need to be increased from its default setting.

When this kind of error occurs, the text String.intern or ClassLoader.defineClass might appear near the top of the stack trace that is printed.

The jmap -permgen command prints statistics for the objects in the permanent generation, including information about internalized String instances. See 2.6.4 Getting Information on the Permanent Generation.)

PermGen又是一个特殊内存区域:Classloader 加载的东东是不能回收的,它们放在PermGen中

(tomcat原文:Why does the memory usage increase when I redeploy a web application? Because the Classloader (and the Class objects it loaded) cannot be recycled. They are stored in the permanent heap generation by the JVM, and when you redepoy a new class loader is created, which loads another copy of all these classes. This can cause OufOfMemoryErrors eventually.)

回到我的问题来,打开%java_home%bin\jvisualvm.exe  (jdk6以上有)

查看tomcat的内存情况,点击tomcat标签下monitor , 当used heap = max heap      used PermGen = max PermGen 时tomcat还在启动中,一会就报错;由于此前已经将myeclipse中server->tomcat->tomcatx.x->jdk的参数设置成-Xms64m -Xmx512m -XX:MaxPermSize=80m

但是monitor 画面中max heap为 256M

点击overview标签,发现jvm参数如下:

-Xms64m
-Xmx512m
-XX:MaxPermSize=80m
-Xms64m
-Xmx256m

显然tomcat使用了最后的设置-Xms64m -Xmx256m;这个是在myeclipse的属性-》java->installed jres 中的vm启动参数里,双击默认启用的jre,把参数去掉或者设置成-Xms64m -Xmx512m

再回到server->tomcat->tomcatx.x->jdk中把-XX:MaxPermSize=80m修改为-XX:MaxPermSize=128m

保存后再启动tomcat,ok

另外,使用jvisualvm持续监测tomcat内存情况发现heap区域的内存使用会在一个高峰后稳定降低,内存被回收了;

而PermGen区域的内存则是不断增加到达一个峰值后就不再增加,但之后此区的内存没有被回收,验证了上面的说法;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值