I have an application that executes some heavy processing in background using java thread pools.
Thread pool are configured to log exceptions occurred during the execution
public enum ExceptionLogger implements Thread.UncaughtExceptionHandler {
INSTANCE;
private static final Logger log = LoggerFactory.getLogger(ExceptionLogger.class);
@Override
public void uncaughtException(Thread t, Throwable e) {
log.error("Exception occurred at thread " + t.getName() + "\n", e);
}
}
In the logs of my application I’m randomly getting java.lang.OutOfMemoryError: Java heap space but if I log memory usage using Runtime.getRuntime().freeMemory() I can see plenty of free heap space available.
In addition application continues working after I get this exception.
Is there any other reason for getting OutOfMemoryError with this message?
You will get an OutOfMemoryError when memory fails to allocate.
This can happen when