即使已增加内存,在Maven上运行时OutOfMemory Java堆空间

我正在编写一些JUnit测试,该测试从MySQL检索200,000条记录。当我尝试通过eclipse运行测试时,它的内存不足。

我通过-Xmx8G的VM参数增加了堆空间,它解决了问题。但是,当我尝试通过调用mvn test在maven上运行此程序时,即使我已将其添加到pom.xml中,它仍然表示内存不足

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
    <reuseForks>true</reuseForks>
    <forkCount>2</forkCount>                        
    <argLine>-Xmx10000m -XX:+HeapDumpOnOutOfMemoryError </argLine>
</configuration>
 
[INFO] Running ABCTechRecords.TestCountUniqueRecord
Nov 03,2019 6:46:44 PM 
ABCTechRecords.TestCountUniqueRecord init
INFO:  Starting test TestA 
[ERROR] Tests run: 1,Failures: 0,Errors: 1,Skipped: 0,Time elapsed: 585.821 s <<< FAILURE! - in ABCTechRecords.TestCountUniqueRecord 
[ERROR] 
TestA(ABCTechRecords.TestCountUniqueRecord )  Time elapsed: 585.801 s  <<< ERROR!
java.lang.OutOfMemoryError: Java heap space at ABCTechRecords.TestCountUniqueRecord.init(TestA.java:28)
st205702 回答:即使已增加内存,在Maven上运行时OutOfMemory Java堆空间

请在pom.xml文件中尝试以下配置。

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <argLine>-Xmx4096m</argLine>
    </configuration>
  </plugin>
</plugins>
本文链接:https://www.f2er.com/3167964.html

大家都在问