JBoss 焊接 + java.lang.OutOfMemoryError: PermGen 空间

发布于 2024-10-29 02:02:10 字数 878 浏览 2 评论 0原文

我刚刚切换到 Weld 以利用 CDI JSF 2 Beans + 对话范围。

这是我的 Maven 依赖项:

    <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 中的条目:

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

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

在使用 Weld 之前,我可以安全地重新加载 Tomcat 7 10 次以上,而不会出现 java.lang.OutOfMemoryError 。我认为在 catalina.sh 中增加 Xmx 选项会有所帮助,但根据我的经验,这并没有帮助。 JAVA_OPTS=-Xmx1024m

这正常吗?

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

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>

Here's the entry in my web.xml :

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

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.

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

Is this normal ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里梦着梦中梦 2024-11-05 02:02:10

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

不,只是开玩笑。 Tomcat 附带的默认 permgen 设置仅为 64MB。其中,Class 定义(即当您执行 Class#forName() 时获得的任何内容)都存储在那里。粗略地说,Weld 扫描类路径中的每个单个 JAR 和类来查找注释,以便它可以以编程方式创建接线配置的内存映射(在注释之前,这通常是通过 XML 文件实现的)。然而,在类路径中包含许多类并加载如此多的类,为 Tomcat 的热部署留下的永久代空间非常小。

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

-XX:MaxPermSize=256m

如果您在 Eclipse 内部使用 Tomcat,则需要通过双击“服务器”视图中的服务器条目、单击“打开启动配置”链接、单击“参数”来进行设置。 /em> 选项卡,然后将其(空格分隔)添加到 VM Arguments 字段。

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

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled

另请参阅:

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

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.

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

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.

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

See also:

淡莣 2024-11-05 02:02:10

尝试设置 permsize:-XX:MaxPermSize=200m。您可能正在加载大量的类定义,因此填满了永久生成空间。

Try setting the permsize: -XX:MaxPermSize=200m. You are probably loading lots of class definitions and therefore filling up the permanent generation space.

宛菡 2024-11-05 02:02:10

除了增加 PermGen 之外,您还应该从 Weld 扫描仪中排除不支持焊接的软件包。请参阅此处:

20.1。从扫描和部署中排除类

<?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:weld="http://jboss.org/schema/weld/beans" 
         xsi:schemaLocation="
            http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
            http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">

      <weld:scan>

          <!-- Don't deploy the classes for the swing app! -->
          <weld:exclude name="com.acme.swing.**" />

          <!-- Don't include GWT support if GWT is not installed -->
          <weld:exclude name="com.acme.gwt.**">
              <weld:if-class-available name="!com.google.GWT"/>
          </weld:exclude>

          <!--
              Exclude classes which end in Blether if the system property verbosity is set to low
              i.e.  java ... -Dverbosity=low            
          -->        
          <weld:exclude pattern="^(.*)Blether$">
              <weld:if-system-property name="verbosity" value="low"/>
          </weld:exclude>

         <!--
               Don't include JSF support if Wicket classes are present, and the viewlayer system
               property is not set
          -->
          <weld:exclude name="com.acme.jsf.**">
              <weld:if-class-available name="org.apahce.wicket.Wicket"/>
              <weld:if-system-property name="!viewlayer"/>
          </weld:exclude>
      </weld:scan>

  </beans>

Except for increasing PermGen, you should also exclude packages, which are not weld-aware, from Weld scanner. See here:

20.1. Excluding classes from scanning and deployment

<?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:weld="http://jboss.org/schema/weld/beans" 
         xsi:schemaLocation="
            http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
            http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">

      <weld:scan>

          <!-- Don't deploy the classes for the swing app! -->
          <weld:exclude name="com.acme.swing.**" />

          <!-- Don't include GWT support if GWT is not installed -->
          <weld:exclude name="com.acme.gwt.**">
              <weld:if-class-available name="!com.google.GWT"/>
          </weld:exclude>

          <!--
              Exclude classes which end in Blether if the system property verbosity is set to low
              i.e.  java ... -Dverbosity=low            
          -->        
          <weld:exclude pattern="^(.*)Blether$">
              <weld:if-system-property name="verbosity" value="low"/>
          </weld:exclude>

         <!--
               Don't include JSF support if Wicket classes are present, and the viewlayer system
               property is not set
          -->
          <weld:exclude name="com.acme.jsf.**">
              <weld:if-class-available name="org.apahce.wicket.Wicket"/>
              <weld:if-system-property name="!viewlayer"/>
          </weld:exclude>
      </weld:scan>

  </beans>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文