java.lang.OutOfMemoryError:使用apache POI读取excel文件时超出了“GC开销限制”

时间:2022-10-09 20:25:54

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 .

我们正在使用Apachi POI从excel文件中读取数据,它为我们的Selenium自动化测试用户提供了800行输入数据。我们已经使用jenkins配置并执行了批处理作业,它工作了一年多。但现在它显示错误“线程中的异常”主“java.lang.OutOfMemoryError:超出GC开销限制”。当我们将JVM内存大小增加到1024 MB时,它工作正常。 excel文件大小只有68KB。但它显示GC错误。能否帮助我们解决问题的原因。我们如何能够为这个问题提供永久的解决方案。

  1. Total rows in the excel sheet is 800
  2. Excel工作表中的总行数为800

  3. excel sheet file size is 68KB
  4. excel表文件大小为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 个解决方案

#1


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.

...意味着您的程序/脚本忙于垃圾收集,JVM无法执行任何进一步的任务。

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.

根据过多的GC Time和OutOfMemoryError,如果在垃圾收集中花费了98%的总时间并且恢复了不到2%的堆内存,则JVM会引发OutOfMemoryError错误。引发此错误是为了防止应用程序长时间运行,而在没有堆内存的情况下没有进展。

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.

注意:无论计算机上安装了多少内存,默认的最大堆大小都不能超过1GB。

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

    通过命令行对Concurrent Collection进行微调:

    -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

您可以在Error java.lang.OutOfMemoryError中找到详细讨论:超出GC开销限制

#1


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.

...意味着您的程序/脚本忙于垃圾收集,JVM无法执行任何进一步的任务。

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.

根据过多的GC Time和OutOfMemoryError,如果在垃圾收集中花费了98%的总时间并且恢复了不到2%的堆内存,则JVM会引发OutOfMemoryError错误。引发此错误是为了防止应用程序长时间运行,而在没有堆内存的情况下没有进展。

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.

注意:无论计算机上安装了多少内存,默认的最大堆大小都不能超过1GB。

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

    通过命令行对Concurrent Collection进行微调:

    -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

您可以在Error java.lang.OutOfMemoryError中找到详细讨论:超出GC开销限制