java Glassfish/Hibernate 的永久代空间问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5509378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 11:28:17  来源:igfitidea点击:

PermGen space issue with Glassfish/Hibernate

javamemory-leaksclassloaderglassfish-3permgen

提问by George Armhold

I'm running a GWT+Hibernate app on Glassfish 3.1. After a few hours, I run out of Permgen space. This is without any webapp reloads. I'm running with –XX:MaxPermSize=256m –XmX1024m.

我在 Glassfish 3.1 上运行 GWT+Hibernate 应用程序。几个小时后,我用完了 Permgen 空间。这是没有任何 webapp 重新加载。我正在与–XX:MaxPermSize=256m –XmX1024m.

I took the advice from this page, and found that I'm leaking tons of classes- all of my Hibernate models and all of my GWT RequestFactory proxies.

我接受了这个页面的建议,发现我泄漏了大量的类——我所有的 Hibernate 模型和我所有的 GWT RequestFactory 代理。

The guide referenced above says to "inspect the chains, locate the accidental reference, and fix the code". Easier said than done.

上面引用的指南说“检查链条,找到意外引用,并修复代码”。说起来容易做起来难。

The classloader always points back to an instance of org.glassfish.web.loader.WebappClassLoader. Digging further, I find lots of references from $Proxy135and similar-named objects. But I don't know how else to follow through.

类加载器始终指向 的实例org.glassfish.web.loader.WebappClassLoader。进一步挖掘,我发现了许多来自$Proxy135类似名称的对象的引用。但我不知道如何跟进。

采纳答案by George Armhold

I "solved" this by moving to Tomcat.

我通过转移到 Tomcat 来“解决”了这个问题。

回答by Dead Programmer

new class objects get placed into the PermGen and thus occupy an ever increasing amount of space. Regardless of how large you make the PermGen space, it will inevitably top out after enough deployments. What you need to do is take measures to flush the PermGen so that you can stabilize its size. There are two JVM flags which handle this cleaning:

新的类对象被放入永久代,因此占据越来越多的空间。无论您的 PermGen 空间有多大,经过足够的部署后,它都将不可避免地达到顶峰。您需要做的是采取措施冲洗 PermGen,以便您可以稳定其大小。有两个 JVM 标志可以处理这种清理:

-XX:+CMSPermGenSweepingEnabled

This setting includes the PermGen in a garbage collection run. By default, the PermGen space is never included in garbage collection (and thus grows without bounds).

此设置包括垃圾回收运行中的 PermGen。默认情况下,永久代空间永远不会包含在垃圾收集中(因此会无限增长)。

-XX:+CMSClassUnloadingEnabled

This setting tells the PermGen garbage collection sweep to take action on class objects. By default, class objects get an exemption, even when the PermGen space is being visited during a garabage collection.

此设置告诉 PermGen 垃圾收集清除对类对象采取行动。默认情况下,类对象获得豁免,即使在垃圾回收期间访问 PermGen 空间也是如此。

回答by Craig Ringer

There are some OK tools to help with this, though you'd never know it. The JDK (1.6 u1 and above) ships with jhat and jmap. These tools will help significantly, especially if you use the jhat JavaScript query support.

有一些不错的工具可以帮助解决这个问题,尽管你永远不会知道。JDK(1.6 u1 及更高版本)附带 jhat 和 jmap。这些工具将有很大帮助,特别是如果您使用 jhat JavaScript 查询支持。

See:

看:

http://blog.ringerc.id.au/2011/06/java-ee-application-servers-learning.html

http://blog.ringerc.id.au/2011/06/java-ee-application-servers-learning.html

http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java

http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java

http://www.mhaller.de/archives/140-Memory-leaks-et-alii.html

http://www.mhaller.de/archives/140-Memory-leaks-et-alii.html

http://blogs.oracle.com/sundararajan/entry/jhat_s_javascript_interface

http://blogs.oracle.com/sundararajan/entry/jhat_s_javascript_interface

回答by Preston

(I can't view the link you provided as it's blocked by websense so if I'm restating anything I apologize)

(我无法查看您提供的链接,因为它被 websense 阻止,因此如果我要重申任何内容,我深表歉意)

It sounds like you have a class loader leak. These are difficult to track down, add these options to the JVM Options in your instance configuration

听起来您有类加载器泄漏。这些很难追踪,将这些选项添加到实例配置中的 JVM 选项

-XX:+PrintGCDetails
-XX:+TraceClassUnloading
-XX:+TraceClassLoading

Now when you run your app, you can look at the jvm.log located in your domain/logs folder and see what's loading and unloading. Mostly likely, you'll see the same class(es) loading over and over again.

现在,当您运行您的应用程序时,您可以查看位于 domain/logs 文件夹中的 jvm.log 并查看正在加载和卸载的内容。很可能,您会看到一遍又一遍地加载相同的类。

A good culprit is JAXB, especially if you're creating a new JAXBContext over and over again.

JAXB 是一个很好的罪魁祸首,尤其是当您一遍又一遍地创建新的 JAXBContext 时。