PermGen 空间错误 - Glassfish 服务器 [英] PermGen space error - Glassfish Server

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

问题描述

我正在使用 Hibernate 和 glassfish Server 运行 Java Web 应用程序.我得到了

I am running java web application using Hibernate and glassfish Server. I am getting

java.lang.OutOfMemoryError: PermGen space 在我多次部署后出现异常.

java.lang.OutOfMemoryError: PermGen space exception when after I deploying it several times.

我在我的环境变量中尝试了 -XX:MaxPermSize=128M,但它不起作用.

I tried -XX:MaxPermSize=128M in my Environment variables, but it doesn't work.

推荐答案

这是类加载器内存泄漏.每次重新部署应用程序时,都会为其创建一个新的类加载器,并再次加载应用程序的所有类.这会消耗永久代空间中的内存.

This is class loader memory leak. Each time you redeploy the application, a new classloader is created for it and all classes of your application are loaded again. This consumes memory in the perm gen space.

旧的类加载器及其所有加载的类都必须进行垃圾回收,否则在多次部署后最终会遇到永久代空间 OOME.如果外部类加载器加载的对象持有对旧类加载器加载的任何对象的引用,则这不起作用.这篇文章很好地解释了这个问题.

The old classloader and all its loaded classes have to be garbage collected, otherwise you will eventually run into a PermGen space OOME after deploying multiple times. This does not work if an object loaded by an outside classloader holds a reference to any object loaded by the old classloader. This article gives a good explanation of the problem.

通常,类加载器泄漏很难分析,有时也很难修复.要找出为什么旧的类加载器没有被垃圾回收,您必须使用分析器.在 JProfiler 中,使用 heap walker,选择 glassfish 类加载器对象并使用传入引用视图,用于检查垃圾收集器根的路径.

Generally, classloader leaks are difficult to analyze and sometimes difficult to fix. To find out why the old classloaders are not garbage collected, you have to use a profiler. In JProfiler, use the heap walker, select the glassfish classloader objects and use the incoming references view to check for paths to garbage collector roots.

类加载器类称为org.apache.servlet.jasper.JasperLoader.这是常规情况的屏幕截图,其中类加载器仅由已加载对象的活动实例持有.

The class loader class is called org.apache.servlet.jasper.JasperLoader. Here's a screenshot of a regular situation, where the class loader is only held by live instances of loaded objects.

在您的情况下,您应该看到来自外部对象的引用.Web 容器中类加载器泄漏的另一个常见原因是后台线程未停止.例如,Google Guice 在 3.0 中就有这样的错误.

In your situation, you should see references from outside objects. Another common cause of a classloader leak in web containers is a background thread that is not stopped. Google Guice for example has such a bug in 3.0.

(免责声明:我公司开发JProfiler)

(Disclaimer: my company develops JProfiler)

这篇关于PermGen 空间错误 - Glassfish 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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