PermGen space

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

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

Sun文档是这样解释的:

java.lang.OutOfMemoryError: PermGen space

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.

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.

下面是某人遇到的问题:

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

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

但问题是为什么这些王牌的开源会出现同一个问题呢,那么是不是更基础的原因呢?tomcat在Q&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最彻底的解决办法就是不要用SUN的JDK,而改用BEA的 JRokit.

在tomcat中redeploy时出现outofmemory的错误.

可以有以下几个方面的原因:

1,使用了proxool,因为proxool内部包含了一个老版本的cglib.

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

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

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

二、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选项设置为相同,而-Xmn为1/4的-Xmx值。
解决方法:手动设置Heap size
修改TOMCAT_HOME/bin/catalina.sh
在“echo "Using CATALINA_BASE:   $CATALINA_BASE"”上面加入以下行:
JAVA_OPTS="-server -Xms 800m -Xmx 800m -XX:MaxNewSize= 256m "

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

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

针对Tomcat,如果Tomcat下面有多个应用,尽可能的把lib下共用的jar文件放到Tomcat的lib下,发布速度和运行速度上也有所提升。

题外话:经常看到网友抱怨tomcat的性能不如...,不稳定等,其实根据笔者几年的经验,从"互联星空“到现在的房产门户网,我们 均使用tomcat作为WEB服务器,每天访问量百万多,tomcat仍然运行良好。建议大家有问题多从自己程序入手,多看看java的DOC文档。

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

PermGen space 1相关推荐

  1. java.lang.OutOfMemoryError: PermGen space及其解决方法

    PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决 ...

  2. 解决 PermGen space Tomcat内存设置

    2019独角兽企业重金招聘Python工程师标准>>> 在使用Java程序从数据库中查询大量的数据或是应用服务器(如tomcat.jboss,weblogic)加载jar包时会出现j ...

  3. 遇java.lang.OutOfMemoryError: PermGen space之解决方案

    昨天项目更新功能但是报了一个永久保存区域溢出的错,导致我所有被SSH调用的方法都不可用,让我很是郁闷了一番,不过这个问题很普遍. 网上一搜,解决方案一大堆.之所以报这个错,原因:PermGen spa ...

  4. IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常

    IntelliJ IDEA的Maven项目在修改时报java.lang.OutOfMemoryError: PermGen space异常 参考文章: (1)IntelliJ IDEA的Maven项目 ...

  5. JAVA编译异常处理:java.lang.OutOfMemoryError: PermGen space

    JAVA编译异常处理:java.lang.OutOfMemoryError: PermGen space 参考文章: (1)JAVA编译异常处理:java.lang.OutOfMemoryError: ...

  6. 解决eclipse报PermGen space异常的问题

    解决eclipse报PermGen space异常的问题 参考文章: (1)解决eclipse报PermGen space异常的问题 (2)https://www.cnblogs.com/zj0208 ...

  7. PermGen space错误解决方法

    2.报错: Exception in thread "DispatcherThread" java.lang.OutOfMemoryError: PermGen space Exc ...

  8. PermGen space

    PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决 ...

  9. Tomcat发布Maven项目遇到异常:java.lang.OutOfMemoryError: PermGen space

    前言: 本问题出现在tomcat 7发布 web3.0Maven项目的时候出现. 问题阐述: 异常:java.lang.OutOfMemoryError:PermGen space 解决如下: 1.  ...

  10. Windows Service方式启动的Tomcat如何配置PermGen Space

    2019独角兽企业重金招聘Python工程师标准>>> 使用Tomcat作为应用服务器并将其注册为Windows系统服务,当Tomcat的webapps下的项目比较多的时候,发现报错 ...

最新文章

  1. 在mybatis中模糊查询有三种写法
  2. SpringAOP静态代理和动态代理
  3. 在unity调用WebService的接口方法
  4. 记录 spring 使用@Value获取properties文件中的属性值
  5. 如何正确使用数据可视化图表
  6. c语言switch同时比较多个变量,C语言学习if和switch分支选择结构
  7. 联动下拉框显示省市县
  8. 求树中某结点的父结点(长子-兄弟表示法)
  9. C#之异步导致内存泄漏
  10. 百度文库收费文档下载方法
  11. 能源路由器 :分布式智能电网应用的混合通信体系结构
  12. 分页存储管理系统中内存有效访问时间的计算
  13. cad一键卸载工具叫什么_autodesk卸载工具一键卸载或安装CAD,3dmax 如何彻底卸载CAD系列软件 | 「讲文兄博客」...
  14. 微信小程序报错 40125 已解决
  15. 真的来了!IO-Link无线-释放传感器/执行器巨大潜力的工业无线解决方案,设备远程监控新选择!(Part 3)
  16. 《联盟》读书笔记(二)
  17. 深交所与庄家6次过招 中集认沽走下神坛幕后
  18. 台式计算机可以连接蓝牙吗,蓝牙耳机怎么连接台式电脑?台式电脑连接蓝牙耳机的方法...
  19. 女朋友生日,我送她网页相册,她感动的哭了(文中有惊喜)
  20. jax-rs jax-ws_了解WS-Policy

热门文章

  1. Linux cp命令的使用方法与参数含义
  2. 1451_TC275 DataSheet阅读笔记12_时钟、温度以及供电
  3. python爬取电子书_python爬取计算机电子书(源码移步github)
  4. PHPMyWind编辑器支持Word上传
  5. 浙江大学 计算机学院的博士,通知 | 浙江大学第377期博士生创新论坛 暨计算机学院第十六届博士生创新论坛(秋冬)报名通知...
  6. 小白学习HCIA2022
  7. C语言:围圈报号排序问题
  8. 计算机考试打字题遇到字母怎么办,手把手为你解决win10系统打字时莫名其妙出现字母的解决方法...
  9. Charles浏览器抓包配置
  10. 美多商城之商品(2)