Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "GC overhead limit exceeded" using maven jvmArg?

When running a class I have the following exception:

Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded

I've tried to increase the jvmArg heap size from inside maven pom.xml of the class package:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<parent>     (...) </parent>   <artifactId>(...)</artifactId> <name>(...)</name>  <properties>     <javaOpts.Xmx>4g</javaOpts.Xmx> <!-- default that can be adjusted on the command line with -DjavaOpts.Xmx=... -->     <(...).basedir>${project.basedir}/..</(...).basedir> </properties>  <build>     <plugins>         <plugin>             <groupId>net.alchim31.maven</groupId>             <artifactId>scala-maven-plugin</artifactId>             <configuration>                 <launchers>                     <launcher>                         <id>MyClassName</id>                         <mainClass>(...)</mainClass>                         <jvmArgs>                             <jvmArg>-Xmx${javaOpts.Xmx}</jvmArg>                         (...)  

I've tried the last cited line with many values:

  • <jvmArg>-Xmx512m{javaOpts.Xmx}</jvmArg>
  • <jvmArg>-Xmx4096M{javaOpts.Xmx}</jvmArg>
  • ...
  • <jvmArg>-Xmx10000000000M{javaOpts.Xmx}</jvmArg>

But for all of them I have the same error.

Anyone can help me? Observation: I'm running from IntelliJ IDEA.

like image 347
Alexandre Cançado Cardoso Avatar asked Sep 12 '13 17:09

Alexandre Cançado Cardoso


People also ask

What causes GC overhead limit exceeded?

lang. OutOfMemoryError: GC overhead limit exceeded" error indicates that the NameNode heap size is insufficient for the amount of HDFS data in the cluster. Increase the heap size to prevent out-of-memory exceptions.

How do I fix GC overhead limit exceeded in eclipse?

From the root of the Eclipse folder open the eclipse. ini and change the default maximum heap size of -Xmx256m to -Xmx1024m on the last line. NOTE: If there is a lot of memory available on the machine, you can also try using -Xmx2048m as the maximum heap size.


2 Answers

Java 7

It's not a Maven issue, you need to give more memory to the VM. You do this via environment variables, and the Maven Launcher will automatically pick up these settings on load, and use them to configure the underlying Java VM.

The simple way to do it is to:

export MAVEN_OPTS="-Xmx1024M -Xss128M -XX:MaxPermSize=1024M -XX:+CMSClassUnloadingEnabled"

Windows:

set MAVEN_OPTS=-Xmx1024M -Xss128M -XX:MaxPermSize=1024M -XX:+CMSClassUnloadingEnabled

(No double quotes)

Java 8

Java 8 has replaced permanent generation with metaspace, and the new settings look like this:

export MAVEN_OPTS="-Xmx1024M -Xss128M -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=1024M -XX:+CMSClassUnloadingEnabled"

like image 171
flavian Avatar answered Oct 11 '22 13:10

flavian


I had kind of the same problem: My project wokspace consists of >250 maven modules and when opening a pom.xml in IDEA, the <project> and <parent> tags were underlined in red and this error showed up, when hovering over the broken tags:

java.lang.OutOfMemoryError: GC overhead limit exceeded

My solution:

  • set high values in >Settings >Build, Execution, Deployment >Build Tools >Maven >Importing - e.g. -Xmx1g and
  • change the maven implementation under >Settings >Build, Execution, Deployment >Build Tools >Maven (Maven home directory) from (Bundled) Maven 3 to my local maven installation (not the one bundled with IDEA), e.g. to /opt/maven/apache-maven-3.3.9: Maven Settings Screenshot

Since I had problems with the bundled maven before, I just don't trust the bundled maven.

like image 24
Alexander Avatar answered Oct 11 '22 11:10

Alexander