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

问题描述

我正在使用Hibernate和glassfish Server运行java web应用程序。当我部署好几次后,我正在获得



java.lang.OutOfMemoryError:PermGen空间异常。 p>

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

解决方案

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



旧的类加载器及其所有加载的类必须被垃圾回收,否则最终会在部署之后遇到一个PermGen空间OOME多次。如果外部类加载器加载的对象持有对旧类加载器加载的任何对象的引用,则不起作用。 可以很好地解释问题。



通常,类加载器泄漏很难分析,有时很难解决。
要找出为什么旧的类加载器不是垃圾回收,你必须使用一个分析器。在中,使用堆步行器,选择glassfish类加载器对象并使用传入引用视图来检查垃圾收集器根的路径。



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





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



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


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

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

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.

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.

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.

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.

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.

(Disclaimer: my company develops JProfiler)

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

09-02 20:01