JBoss Weld + java.lang.OutOfMemoryError:PermGen空间 [英] JBoss Weld + java.lang.OutOfMemoryError: PermGen space

查看:163
本文介绍了JBoss Weld + java.lang.OutOfMemoryError:PermGen空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚切换到Weld使用CDI JSF 2 Beans +会话范围。

I've just switched to Weld to make use of CDI JSF 2 Beans + conversation scope.

这是我的maven依赖:

Here's my maven dependency :

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>1.0.1-Final</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

这是我的web.xml中的条目:

Here's the entry in my web.xml :

<listener>
  <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

我立即注意到的一件事是我需要重新加载我的tomcat 7 2次, java.lang.OutOfMemoryError:PermGen space 将显示在catalina.out日志文件中。

One thing i noticed immediately is i just need to reload my tomcat 7 for like 2 times, and the java.lang.OutOfMemoryError: PermGen space will show up in catalina.out log file.

在使用Weld之前,我可以在没有java.lang.OutOfMemoryError的情况下安全地重新加载我的tomcat 7超过10次。我认为在catalina.sh中增加我的Xmx选项会有所帮助,但这并不符合我的经验。 JAVA_OPTS = -Xmx1024m

Before using Weld, i can reload my tomcat 7 for like more than 10 times safely without the java.lang.OutOfMemoryError . I thought increasing my Xmx option in catalina.sh would help, but it didnt in my experience. JAVA_OPTS=-Xmx1024m

这是正常的吗?

推荐答案

当您想使用一个不是为此设计的简单servlet容器来使用Java EE时,这确实是一个非常典型的错误;)

This is indeed a very typical error when you want to go Java EE with a simple servletcontainer which isn't designed for that ;)

不,只是在开玩笑。 Tomcat的默认permgen设置仅为64MB。其中 Class 定义(即当您执行 Class#forName()时获得的任何内容)都存储在那里。粗略地说,Weld在类路径中扫描每个单个JAR和类以查找注释,以便它可以以编程方式创建布线配置的内存映射(在通常由XML文件实现的注释之前)。但是,在类路径中有许多类并加载那么多类,在permgen空间中留下很少的空间用于Tomcat的热部署。

No, just kidding. Tomcat ships with a default permgen setting of only 64MB. Among others the Class definitions (i.e. whatever you get when you do Class#forName()) are stored there. Roughly put, Weld scans every single JAR and class in the classpath to find the annotations so that it can programmatically create a memory mapping of the wiring configuration (before annotations this was typically achieved by XML files). However, having many classes in the classpath and loading that much classes leaves very little room in permgen space for hotdeploys of Tomcat.

有几种方法可以解决这个问题。最合乎逻辑的方法是增加permgen空间。您可以将其设置为VM参数。 256MB是一个好的开始。

There are several ways to go around this. Most logical way would be to increase the permgen space. You can set it as a VM argument. 256MB is a good start.

-XX:MaxPermSize=256m

如果你在Eclipse中使用Tomcat,你需要通过双击 Servers 视图中的服务器条目来设置它,点击打开启动配置链接,单击 Arguments 选项卡,然后将其添加(空格分隔)到 VM Arguments 字段。

If you're using Tomcat from inside Eclipse, you need to set it by doubleclicking the server entry in Servers view, clicking Open launch configuration link, clicking Arguments tab and then adding it (space separated) to the VM Arguments field.

此外,您还可以强制JVM更加谨慎地使用permgen空间。默认情况下很少卸载其中的对象。添加以下VM参数。

Further, you can also force JVM to be more sparingly with the permgen space. Objects in there are by default rarely unloaded. Add the following VM Arguments.

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled



参见:




  • Tomcat Wiki - OutOfMemory错误

  • See also:

    • Tomcat Wiki - OutOfMemory errors
    • 这篇关于JBoss Weld + java.lang.OutOfMemoryError:PermGen空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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