Search code examples
javamultithreadingmaven-surefire-plugin

Maven Throws "java.lang.OutOfMemoryError" when generating Sure-fire reports


I know this question appeared all along long time, but none of the solution worked successful to me

Maven throws "java.lang.OutOfMemoryError"

How to deal with "java.lang.OutOfMemoryError: Java heap space" error?

though I tried above two solutions, and also tried other options suggested by other answers still I was ended up in the below error

17-Dec-2018 11:36:54    Exception in thread "ForkJoinPool.commonPool-worker-5" java.lang.OutOfMemoryError: unable to create new native thread
17-Dec-2018 11:36:54            at java.lang.Thread.start0(Native Method)
17-Dec-2018 11:36:54            at java.lang.Thread.start(Thread.java:717)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinPool.createWorker(ForkJoinPool.java:1486)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinPool.tryAddWorker(ForkJoinPool.java:1517)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinPool.deregisterWorker(ForkJoinPool.java:1609)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:167)
17-Dec-2018 11:36:54    Exception in thread "ForkJoinPool.commonPool-worker-0" java.lang.OutOfMemoryError: unable to create new native thread
17-Dec-2018 11:36:54            at java.lang.Thread.start0(Native Method)
17-Dec-2018 11:36:54            at java.lang.Thread.start(Thread.java:717)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinPool.createWorker(ForkJoinPool.java:1486)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinPool.tryAddWorker(ForkJoinPool.java:1517)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinPool.deregisterWorker(ForkJoinPool.java:1609)
17-Dec-2018 11:36:54            at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:167)

to make it clear,

I have used sure-fire to run the testng tests and generate the report accordingly... so I first applied the approach to add the argline, it doesn't help. then I tried adding MAVEN_OPTS and increased values ranging from 256 to 1024 that doesn't works either finally added JAVA_TOOL_OPTIONS, still it doesn't works even though i tried multiple values to specify

Are there any other choices left to try out to resolve the problem

Don't mark this duplicate... I need a better solution than already existing.

Edited

Hardware Details using command lscpu

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    4
Socket(s):             2
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 61
Model name:            Intel Core Processor (Broadwell)
Stepping:              2
CPU MHz:               2197.454
BogoMIPS:              4394.90
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0-7

OS Details using uname -a

Linux pt-00-00 3.10.0-327.4.5.el7.x86_64 #1 SMP Thu Jan 21 04:10:29 EST 2016 x86_64 x86_64 x86_64 GNU/Linux

Details for cat /proc/meminfo

MemTotal:       24517356 kB
MemFree:        24048256 kB
MemAvailable:   24054212 kB
Buffers:           35556 kB
Cached:           142932 kB
SwapCached:            0 kB
Active:            81092 kB
Inactive:         144820 kB
Active(anon):      47652 kB
Inactive(anon):    24724 kB
Active(file):      33440 kB
Inactive(file):   120096 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:       4193276 kB
SwapFree:        4193276 kB
Dirty:                 8 kB
Writeback:             0 kB
AnonPages:         47688 kB
Mapped:            40864 kB
Shmem:             24896 kB
Slab:              55872 kB
SReclaimable:      27304 kB
SUnreclaim:        28568 kB
KernelStack:        5520 kB
PageTables:         4180 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    16451952 kB
Committed_AS:     238360 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      169716 kB
VmallocChunk:   34359564288 kB
HardwareCorrupted:     0 kB
AnonHugePages:     12288 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       63344 kB
DirectMap2M:    25102336 kB

Details for vmstat -s

 24517356 K total memory
   234276 K used memory
    81704 K active memory
   145092 K inactive memory
 24048760 K free memory
    35656 K buffer memory
   198664 K swap cache
  4193276 K total swap
        0 K used swap
  4193276 K free swap
     3630 non-nice user cpu ticks
       24 nice user cpu ticks
     6329 system cpu ticks
 21548595 idle cpu ticks
     1549 IO-wait cpu ticks
        0 IRQ cpu ticks
       16 softirq cpu ticks
       25 stolen cpu ticks
   142239 pages paged in
   101165 pages paged out
        0 pages swapped in
        0 pages swapped out
  1169647 interrupts
  1713506 CPU context switches
   1546461109 boot time
        50951 forks

Solution

  • You can configure the maven-surefire-plugin like this:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>x.x.x</version>
        <configuration>
            <argLine>-Xmx2048m -XX:MaxPermSize=1024m</argLine>
        </configuration>
      </plugin>
    

    to set JVM arguments.