weblogic报java.lang.OutOfMemoryError: PermGen space

内存溢出是软件开发过程中经常遇到的一些问题,在本地使用weblogic中间件的时候,可能会经常打包部署应用,重复多次之后,就可能出现内存溢出的情况。

1 发现问题

在部署的时候,遇到相同的包,一般直接使用“更新”功能,更新多次之后,发现项目部署的越来越慢,而且还会打印java.lang.OutOfMemoryError: PermGen space,OutOfMemoryError是内存溢出,PermGen space说明是永久代(即方法区)发生异常。

2 分析问题

在Tomcat的Wiki页面中记录过这种问题:

Why does the memory usage increase when I redeploy a web application?

That is because your web application has a memory leak.

A common issue are “PermGen” memory leaks. They happen because the Classloader (and the Class objects it loaded) cannot be recycled unless some requirements are met (*). They are stored in the permanent heap generation by the JVM, and when you redeploy a new class loader is created, which loads another copy of all these classes. This can cause OufOfMemoryErrors eventually.

(*) The requirement is that all classes loaded by this classloader should be able to be gc’ed at the same time.

这也算是它山之石可以攻玉了。产生上面问题应该也是JVM虚拟机对永久代区域的内容做垃圾回收造成应用动态加载类文件过多引起的内存溢出错误。

3 解决问题

在weblogic域的bin目录中(我的是D:\Develop\Weblogic\wls12120\user_projects\domains\mydomain\bin)的setDomainEnv.cmd(linux对应修改setDomainEnv.sh),,查找-XX:MaxPermSize:

set MEM_MAX_PERM_SIZE_64BIT=-XX:MaxPermSize=256mset MEM_MAX_PERM_SIZE_32BIT=-XX:MaxPermSize=256m

这个参数是设置永久代区域的最大值,默认是256M,直接改成512M(可以根据自己电脑配置适当增大),保存,然后重新启动weblogic。发现weblogic运行速度加快,并且只有当本机内存被其他应用占用很多的时候才会再次出现这种错误。

问题解决。

注:PermGen space,permanent heap generation space,即永久代或方法区。

自己选择的路,跪着也要把它走完。

weblogic报java.lang.OutOfMemoryError: PermGen space

相关文章:

你感兴趣的文章:

标签云: