JBoss 焊接 + java.lang.OutOfMemoryError: PermGen 空间
我刚刚切换到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您想要使用一个简单的 servlet 容器(该容器不是为此设计的)使用 Java EE 时,这确实是一个非常典型的错误;)
不,只是开玩笑。 Tomcat 附带的默认 permgen 设置仅为 64MB。其中,
Class
定义(即当您执行Class#forName()
时获得的任何内容)都存储在那里。粗略地说,Weld 扫描类路径中的每个单个 JAR 和类来查找注释,以便它可以以编程方式创建接线配置的内存映射(在注释之前,这通常是通过 XML 文件实现的)。然而,在类路径中包含许多类并加载如此多的类,为 Tomcat 的热部署留下的永久代空间非常小。有几种方法可以解决这个问题。最合乎逻辑的方法是增加永久代空间。您可以将其设置为 VM 参数。 256MB 是一个好的开始。
如果您在 Eclipse 内部使用 Tomcat,则需要通过双击“服务器”视图中的服务器条目、单击“打开启动配置”链接、单击“参数”来进行设置。 /em> 选项卡,然后将其(空格分隔)添加到 VM Arguments 字段。
此外,您还可以强制 JVM 更加节约地使用 permgen 空间。默认情况下,其中的对象很少被卸载。添加以下 VM 参数。
另请参阅:
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 doClass#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.
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.
See also:
尝试设置 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.除了增加 PermGen 之外,您还应该从 Weld 扫描仪中排除不支持焊接的软件包。请参阅此处:
20.1。从扫描和部署中排除类
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