Home > other >  Spring Batch : java.lang.OutOfMemoryError: Java heap space
Spring Batch : java.lang.OutOfMemoryError: Java heap space

Time:09-17

As part of a Spring Batch job, we are processing 1TB worth of data to our system.

After the process running for 4-5hours getting the OOM, when the job is terminated ideally the java heap has to be cleared. and when restarted it should start on the fresh heap. but for some reason when checked with jcmd -gccapacity OGC and OC values are showing full. How do we clear the Heap and restart the job as good as new run? This is production env, in lower env we had very less data so did not face any issue. meanwhile i am debugging the memory leaks in code. NOTE: We already used the -Xmx to 8GB.

NGCMN    NGCMX     NGC     S0C   S1C       EC      OGCMN      OGCMX       OGC         OC       MCMN     MCMX      MC     CCSMN    CCSMX     CCSC    YGC    FGC   CGC
     0.0 4194304.0 220160.0    0.0    0.0 220160.0        0.0  4194304.0  3974144.0  3974144.0      0.0 1224704.0 203840.0      0.0 1048576.0  28672.0    112     4    83

Please advice. Appreciate your help.

CodePudding user response:

When you start your JVM the command line should also contain a "scheme" for using the G1 garbage collector. This should be on the command-line or within configuration files for the program startup -XX: UseG1GC followed by parameters of a scheme on how to share memory for cleanup (runtime behavior) by the G1. It is usually set when -Xms and -Xmx and -Xss are used to assign and reserve RAM for the JVM on starup. In code, after large data routines are finished , using System.gc() requests the garbage collector take a look to clean up at its discretion(it will in near future).

CodePudding user response:

     intx CompilerThreadStackSize                  = 1024                                   {pd product} {default}
   size_t ErgoHeapSizeLimit                        = 0                                         {product} {default}
   size_t HeapSizePerGCThread                      = 43620760                                  {product} {default}
   size_t InitialHeapSize                          = 511705088                                 {product} {ergonomic}
   size_t LargePageHeapSizeThreshold               = 134217728                                 {product} {default}
   size_t MaxHeapSize                              = 8183087104                                {product} {ergonomic}
    uintx NonNMethodCodeHeapSize                   = 7594288                                {pd product} {ergonomic}
    uintx NonProfiledCodeHeapSize                  = 122031976                              {pd product} {ergonomic}
    uintx ProfiledCodeHeapSize                     = 122031976                              {pd product} {ergonomic}
   size_t ShenandoahSoftMaxHeapSize                = 0                                      {manageable} {default}
     intx ThreadStackSize                          = 1024                                   {pd product} {default}
     bool UseG1GC                                  = true                                      {product} {ergonomic}
    ```
  • Related