Reputation: 33
I've looked into a lot of places and couldn't find the reason for a JVM to die due to an OOM. I'm not considering the OS killer. To give some context, I have a Java application running and it starts to run out of memory, I know it may survive after the JVM start killing the threads.
However, I've seen it running for more than 30 minutes after the first OOM and it keeps running in this unresponsive state, it may or not recover. But, I've also seen it crashing right after the first OOM after replicating the same steps to trigger the OOM. The system is fine in the memory side, the problem is just with the JVM. So, my questions are:
Upvotes: 3
Views: 1974
Reputation: 308021
Technically an OutOfMemoryError
is "just another throwable", so it may or may not kill the thread it is being thrown in, depending on how that Thread handles its exceptions.
For example, if it has a catch (Error e)
block at the lowest level then it can "withstand" a lot of problems while still running.
So if your OutOfMemoryError
is only thrown in threads that handle errors like this gracefully then your system can continue working just fine.
But that is also where the 2 unusual property of OutOfMemoryError
comes into play:
OOME
incredibly hard.If you want to be truly resilient to OOMs in your application, you must ensure that all threads either gracefully handle OutOfMemoryError
s or are restarted correctly when they don't (via a watchdog or something similar). That's often quite difficult to do, especially when using any libraries that create their own threads.
So the tl;dr answers to your questions are:
Upvotes: 4