Maven Jetty Plugin OutOfMemoryError When Sharing Instance Between Two Web Apps

别等时光非礼了梦想. 提交于 2020-01-13 03:38:08

问题


I'm using the maven jetty plugin to run my two web applications. One web application is spring mvc UI and the other is a RESTful web application. I able to get the two web applications to communicate when I run two separate mvn jetty:run instances and assign different ports. I have successfully deploy both in the same jetty instance using the same port using the below maven pom.xml configuration. I eventually get a ava.lang.OutOfMemoryError: PermGen space error. What is the best workaround for this?

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.6.8.v20121106</version>
    <configuration>
        <jvmArgs>-Xmx2024m -Xms2024m</jvmArgs>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <webApp>
            <contextPath>/</contextPath>
        </webApp>
        <contextHandlers>           
            <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                <war>../../api/target/main-api.war</war>
                <contextPath>/test</contextPath>
            </contextHandler>
        </contextHandlers> 
    </configuration>
</plugin>

回答1:


Add following jvm argument, if you get error regarding cannot allocate memory then try using lesser value (128 and 256)

-XX:PermSize=256M -XX:MaxPermSize=512M

Reference

  • What is 'PermSize' in Java?
  • -XX:MaxPermSize with or without -XX:PermSize



回答2:


Try running Jetty in forked mode like this:

<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.6.8.v20121106</version>
    <executions>
        <execution>
          <id>start-jetty</id>
          <!-- Set this to the appropriate phase:
               pre-integration-test, or earlier test-compile-->
          <phase>pre-integration-test</phase>
          <goals>
             <goal>run-forked</goal>
          </goals>
       </execution>
    </executions>

    <configuration>
        <jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=128m -XX:MaxPermSize=256m</jvmArgs>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <webApp>
            <contextPath>/</contextPath>
        </webApp>
        <contextHandlers>           
            <contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
                 <war>../../api/target/main-api.war</war>
                <contextPath>/test</contextPath>
            </contextHandler>
        </contextHandlers> 
    </configuration>
</plugin>

For more details check Running Jetty in a forked JVM.

And... Make sure you really have 2048 MB of free RAM before starting this.




回答3:


Try using Plumbr to diagnose any memory leak issues with both your web apps. http://plumbr.eu/




回答4:


I eventually get a java.lang.OutOfMemoryError: PermGen space error

How long is eventually? Is one of the webapps redeploying frequently due to changes?

It is very easy to leak classes when redeploying a web app. I would run maven with this setting added to MAVEN_OPTS

-XX:+HeapDumpOnOutOfMemoryError

Run until you get an out of memory error, then load the dump with eclipse mat and see what is filling up your perm gen. Most likely your web app is leaking classes on redeploy.




回答5:


It depends on which JVM instance require more memory. As example, if tests are forked (by default), and fails due OutOfMemoryError then try configure plugin which launching them:

   <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <argLine>-Xmx1024m</argLine>
        </configuration>
    </plugin>

OR

Apart from heap memory. You have to increase perm size also to resolve that exception in maven use these variables in environment variable. And Sometimes is good also to extend perm memory size -

Set the environment variable:

variable name: MAVEN_OPTS variable value: -Xmx512m -XX:MaxPermSize=256m

Compiled data from resource




回答6:


Please clarify: what jvm version you are using, what operating system you are on, how many physical memory is installed on your computer. What happen if you reduce your memory requirements for example to 1400M (it could help if you run on 32bit jvm), i.e.:

<jvmArgs>-Xmx1400m -Xms1400m</jvmArgs>


来源:https://stackoverflow.com/questions/18669345/maven-jetty-plugin-outofmemoryerror-when-sharing-instance-between-two-web-apps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!