What's the best way to handle java.lang.OutOfMemor...
# spring
r
What's the best way to handle java.lang.OutOfMemory Error? Usually I let it propagate to the JVM/Docker container so the instance get’s killed / restarted. In my current application this error get’s caught in the Tomcat server of spring boot and I don't know why … any clues?
😶 4
j
You don't handle the error in code. The way to handle it is to write good code that doesn't throw the error. There are tools you can use to analyze the heap to determine what is eating up your memory
k
There are 2 options: memory leak or misconfiguration of your JVM. In case of former you need to find it and fix using heap analysers. Run a load test for a while on your app and then capture the heap to see which objects are eating the memory. Or configure the JVM to save heap dump on prod when OOM happens and then analyse it. If in your heap everything seems reasonable, it means you app just consumes more memory than you configured. Just increase the heap size for the app.
There could be easier option as well: Just double the size of the heap for your tomcat and configure daily restarts :)
r
I don't have a memory leak, I want to know how my application will behave in case.
It's running in docker / k8s. When I run it via docker compose and trigger an OOM, the container gets killed (which I want) In k8s the application just keeps running unresponsive … but this is now clearly 😶 anymore.
167 Views