java.lang.OutOfMemoryError: GC overhead limit exce

2019-03-06 16:28发布

问题:

We are reading data from the excel file using Apachi POI, It has 800 rows of input data for our Selenium automation testcases. We have configured using jenkins and executed the batch jobs and it was working fine for more than a year . but now it shows error that "Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded". when we increase the JVM memory size as 1024 MB it is working fine. The excel file size is only 68KB. but it shows GC error. Could you please help us what is the cause of the issue . how we can give the pemanent fix for the issue .

  1. Total rows in the excel sheet is 800
  2. excel sheet file size is 68KB

Getting error message as:

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

Please find the attached screenshot for the refrence enter image description here

回答1:

This error message...

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

...implies that your program/script is busy in garbage collection and JVM is unable to perform any further task.

As per Excessive GC Time and OutOfMemoryError OutOfMemoryError error is raised by the JVM if 98% of the total time is spent in garbage collection and less than 2% of the heap memory is recovered. This error is raised to prevent applications from running for an extended period of time while making no progress in absence of heap memory.

Solution

  • Turn off the feature which shows this error message by adding an option through the command line as:

    -XX:-UseGCOverheadLimit
    
  • Increase the heap size through the command line as:

    -Xmx1g
    

Note: The default maximum heap size can't exceed 1GB limit regardless of how much memory is installed on the machine.

  • Fine tune the Concurrent Collection through the command line as:

    -XX:CMSInitiatingOccupancyFraction=<N>
    
  • Enable the incremental mode:

    -XX:+CMSIncrementalMode
    
  • Enable automatic pacing:

    -XX:+CMSIncrementalPacing
    
  • Finally, ensure that there are no Memory Leaks in your program.

  • Most importantly, try to reuse the existing objects whenever and whereever possible to save memory.

You can find a detailed discussion in Error java.lang.OutOfMemoryError: GC overhead limit exceeded