PermGen space

PermGen space php

PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决方法也必定是加大内存。说说为何会内存益出:这一部分用于存放ClassMeta的信息,Class在被 Load的时候被放入PermGen space区域,它和和存放InstanceHeap区域不一样,GC(Garbage Collection)不会在主程序运行期对PermGen space进行清理,因此若是你的APPLOAD不少CLASS的话,就极可能出现PermGen space错误。这种错误常见在web服务器对JSP进行pre compile的时候。 若是你的WEB APP下都用了大量的第三方jar, 其大小 超过了jvm默认的大小(4M)那么就会产生此错误信息了。
解决方法: 手动设置MaxPermSize大小
改正方法:-Xms256m-Xmx256m-XX:MaxNewSize=256m-XX:MaxPermSize=256mhtml

 

修改TOMCAT_HOME/bin/catalina.sh
JAVA_OPTS="-server -XX:PermSize=64M-XX:MaxPermSize=128m
建议:将相同的第三方jar文件移置到tomcat/shared/lib目录下,这样能够达到减小jar 文档重复占用内存的目的。

java

Sun文档是这样解释的:web

java.lang.OutOfMemoryError: PermGen spacespring

The detail message PermGen space indicates that the permanent generation is full. The 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.tomcat

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.app

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.less

下面是某人遇到的问题:jvm

SUN JDK+Tomcat5.5.20运行服务的时候遇到问题,服务器跑几天后就会挂掉,并报java.lang.OutOfMemoryError: PermGen space异常。

发现不少人把问题归因于: spring,hibernate,tomcat,由于他们动态产生类,致使JVM中的permanent heap溢出 。而后解决方法众说纷纭,有人说升级 tomcat版本到最新甚至干脆不用tomcat。还有人怀疑spring的问题,在spring论坛上讨论很激烈,由于springAOP时使用CBLIB会动态产生不少类。

但问题是为何这些王牌的开源会出现同一个问题呢,那么是否是更基础的缘由呢?tomcatQ&A很隐晦的回答了这一点。(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.

因而有人对更基础的JVM作了检查,发现了问题的关键。原来SUN JVM把内存分了不一样的区,其中一个就是permanent区用来存放用得很是多的类和类描述。原本SUN设计的时候认为这个区域在JVM启动的时候就固定了,但他没有想到如今动态会用得这么普遍。并且这个区域有特殊的垃圾收回机制,如今的问题是动态加载类到这个区域后,gc根本没办法回收!

对这个bug最完全的解决办法就是不要用SUNJDK,而改用BEA JRokit.

 

tomcatredeploy时出现outofmemory的错误.

能够有如下几个方面的缘由:

,使用了proxool,由于proxool内部包含了一个老版本的cglib.

2, log4j,
最好不用,只用common-logging

3,
老版本的cglib,快点更新到最新版。

4,更新到最新的hibernate3.2
3
这里以tomcat环境为例,其它WEB服务器如jboss,weblogic等是同一个道理。

 

2、java.lang.OutOfMemoryError: Java heap space
Heap size
设置
JVM
堆的设置是指java程序运行过程当中JVM能够调配使用的内存空间的设置.JVM在启动的时候会自动设置Heap size的值,
其初始空间(-Xms)是物理内存的1/64,最大空间(-Xmx)是物理内存的1/4。能够利用JVM提供的-Xmn -Xms -Xmx等选项可
进行设置。Heap size 的大小是Young Generation Tenured Generaion 之和。
提示:在JVM中若是98%的时间是用于GC且可用的Heap size 不足2%的时候将抛出此异常信息。
提示:Heap Size 最大不要超过可用物理内存的80%,通常的要将-Xms-Xmx选项设置为相同,而-Xmn1/4-Xmx值。
解决方法:手动设置Heap size
修改TOMCAT_HOME/bin/catalina.sh
“echo "Using CATALINA_BASE:   $CATALINA_BASE"”上面加入如下行:
JAVA_OPTS="-server -Xms800m-Xmx800m   -XX:MaxNewSize=256m"

3、实例,如下给出1G内存环境下java jvm 的参数设置参考:

JAVA_OPTS="-server -Xms800m-Xmx800m  -XX:PermSize=64M -XX:MaxNewSize=256m-XX:MaxPermSize=128m-Djava.awt.headless=true "


针对Tomcat,若是Tomcat下面有多个应用,尽量的把lib下共用的jar文件放到Tomcatlib下,发布速度和运行速度上也有所提高。

 

题外话:常常看到网友抱怨tomcat的性能不如...,不稳定等,其实根据笔者几年的经验,从"互联星空到如今的房产门户网,咱们 均使用tomcat做为WEB服务器,天天访问量百万多,tomcat仍然运行良好。建议你们有问题多从本身程序入手,多看看javaDOC文档。

参考文档:http://blogs.sun.com/jonthecollector/entry/presenting_the_permanent_generation

相关文章
相关标签/搜索