【问题标题】:PermGen space with jetty带码头的 PermGen 空间
【发布时间】:2014-03-02 00:53:37
【问题描述】:

我正在开发一个 java web 应用程序,我正在使用类似 maven 的项目管理工具。现在我的问题是,如果我以这种方式将码头设置为每 20 秒自动扫描一次:

<!-- To launch embded jetty server -->
       <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                    <extraClasspath>target/classes;../services/target/classes;</extraClasspath>
                </webAppConfig>
                <scanTargets>
                    <scanTarget>target/classes</scanTarget>
                    <scanTarget>../services/target/classes</scanTarget>
                </scanTargets>
            </configuration>
        </plugin>

Jetty 以正确的方式启动,事实上我明白了:

[INFO] 已启动 Jetty 服务器

[INFO] 每隔 20 秒启动一次扫描仪。

但在第一次扫描时,我收到以下错误:

ERROR ContextLoader - 上下文初始化失败

java.lang.OutOfMemoryError: PermGen 空间

我该如何解决?

更新 1

我尝试以这种方式从我的 Eclipse Ide 中增加 PermGen 空间:

但在第一次扫描后,我得到了同样的错误。

我该如何解决?

【问题讨论】:

  • 这意味着当你的 webapp 重新部署时,你的 webapp 的类加载器没有被卸载。也许你已经定义了 ThreadLocals?
  • 我不知道 ThreadLocals 的意思,你能解释一下可能是什么问题并链接解决它
  • 如果你不知道什么是 ThreadLocals,你可能没有使用它们。 :) 但是类加载器肯定没有被卸载。

标签: java maven jetty maven-3


【解决方案1】:

将此放在&lt;configuration&gt; 元素下:&lt;jvmArgs&gt;-XX:PermSize=256M -XX:MaxPermSize=512M&lt;/jvmArgs&gt;

因此 Maven 插件将如下所示:

<!-- To launch embded jetty server -->
       <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>${maven-jetty-plugin.version}</version>
            <configuration>
                <jvmArgs>-XX:PermSize=256M -XX:MaxPermSize=512M</jvmArgs>
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <webAppConfig>
                    <contextPath>/${project.name}</contextPath>
                    <extraClasspath>target/classes;../services/target/classes;</extraClasspath>
                </webAppConfig>
                <scanTargets>
                    <scanTarget>target/classes</scanTarget>
                    <scanTarget>../services/target/classes</scanTarget>
                </scanTargets>
            </configuration>
        </plugin>

注意:如果失败并显示无法分配这么多内存的消息,请使用较小的数字。

【讨论】:

  • 感谢您的建议,但还不行。我快疯了:(
【解决方案2】:

你试过在JDK8下运行吗? PermGen 已被 MetaSpace 取代,可能会解决您的 PermGen 问题:http://www.infoq.com/news/2013/03/java-8-permgen-metaspace

Jetty 也有一些关于防止类加载器泄漏可能会填满 permgen 的文档:http://www.eclipse.org/jetty/documentation/current/preventing-memory-leaks.html

【讨论】:

    【解决方案3】:

    尝试通过将 -XX:MaxPermSize=512m 传递给 MAVEN_OPTS 来增加 MaxPermGen 空间。

    【讨论】:

      猜你喜欢
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 2011-09-04
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多