OutOfMemoryError is a subclass of java.lang.VirtualMachineError; it’s thrown by the JVM when it faces a problem linked to using resources. More particularly, the error occurs when the JVM consumed too much time performing Garbage Collection and was only able to recover very little heap space.
According to Java docs, by default, the JVM is configured to throw this error if the Java method spends more than 98% of its time doing GC and when only less than 2% of the heap is collected in each run. In other words, this means that our application has consumed nearly all the available memory and the Garbage Collector has consumed too much time trying to clean it and failed regularly.
In this situation, users experience excessive slowness of the application. Some operations, which usually finished in milliseconds, take more time to finish. This is because the CPU is using its complete capacity for Garbage Collection and hence cannot perform any other tasks.
To fix this error turn this off with the command line option -XX:-UseGCOverheadLimit
To know more about it click here.