java.lang.OutOfMemoryError: JVM of the batch is not stopped
10:10 07 Jan 2026

I have a Spring boot application with batches.

I have the following error when doing a select in a batch:

java.lang.OutOfMemoryError: Cannot reserve 1048576 bytes of direct buffer memory (allocated: 9695196, limit: 10485760)
at java.nio.Bits.reserveMemory(Unknown Source)
at java.nio.DirectByteBuffer.(Unknown Source)
...

I tried to catch the Throwable to have a log in a result table but it is not possible. The "main" thread does not continue the code and the log is not called (does not appear in the log file: I have a log before the select and then the error log without the log in the catch).

What I saw is that the error seems to be logued with an other thread of the JVM (not the "main" one but by "reactor-http-epoll-3" thread).

The JVM is not stopped when this exception is thrown (I have to kill the process myself). I have this in the main:

public static void main(String[] args) {
        System.exit(SpringApplication.exit(SpringApplication.run(MyBatchLauncher.class, args)));
}

Is it possible to catch the error and stop the JVM properly please?

java spring spring-boot