简体   繁体   English

Glassfish / Hibernate的PermGen空间问题

[英]PermGen space issue with Glassfish/Hibernate

I'm running a GWT+Hibernate app on Glassfish 3.1. 我正在Glassfish 3.1上运行GWT + Hibernate应用程序。 After a few hours, I run out of Permgen space. 几个小时后,我跑出了Permgen空间。 This is without any webapp reloads. 这没有任何webapp重新加载。 I'm running with –XX:MaxPermSize=256m –XmX1024m . 我正在使用–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 . 类加载器始终指向org.glassfish.web.loader.WebappClassLoader的实例。 Digging further, I find lots of references from $Proxy135 and similar-named objects. 进一步深入,我发现了许多来自$Proxy135和类似命名对象的引用。 But I don't know how else to follow through. 但我不知道还有什么可以贯彻的。

new class objects get placed into the PermGen and thus occupy an ever increasing amount of space. 新的类对象被放入PermGen中,从而占用越来越多的空间。 Regardless of how large you make the PermGen space, it will inevitably top out after enough deployments. 无论你制作PermGen空间有多大,它都将在经过足够的部署后不可避免地达到顶峰。 What you need to do is take measures to flush the PermGen so that you can stabilize its size. 你需要做的是采取措施冲洗PermGen,以便你可以稳定它的大小。 There are two JVM flags which handle this cleaning: 有两个JVM标志可以处理这种清理:

-XX:+CMSPermGenSweepingEnabled

This setting includes the PermGen in a garbage collection run. 此设置包括垃圾收集运行中的PermGen。 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. 此设置告诉PermGen垃圾收集扫描对类对象执行操作。 By default, class objects get an exemption, even when the PermGen space is being visited during a garabage collection. 默认情况下,即使在garabage集合期间访问PermGen空间时,类对象也会获得免除。

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

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. JDK(1.6 u1及以上版本)附带jhat和jmap。 These tools will help significantly, especially if you use the jhat JavaScript query support. 这些工具将有很大帮助,特别是如果您使用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

(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. 现在,当您运行应用程序时,您可以查看位于domain / logs文件夹中的jvm.log,查看正在加载和卸载的内容。 Mostly likely, you'll see the same class(es) loading over and over again. 很可能,你会看到相同的类一次又一次地加载。

A good culprit is JAXB, especially if you're creating a new JAXBContext over and over again. 一个好的罪魁祸首是JAXB,特别是如果你一遍又一遍地创建一个新的JAXBContext。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM