0

I would like to understand a strategy, if any, about how to react on Out Of Memory heap errors / OOM errors in Java.

To my current understanding, these errors "break" the program so the code itself might stop (or substantaily slow down) performing.

However for example Hazelcast seem to have some technology that deals with such situations.

Yet, I would like to add in my code a fail-over routine that for instance shots program down gracefully and/or trigger external scripts that take care of memdumps, alerts and the like.

Askar Ibragimov
  • 6,494
  • 15
  • 65
  • 132
  • 1
    Potentially relevant: https://stackoverflow.com/questions/542979/using-heapdumponoutofmemoryerror-parameter-for-heap-dump-for-jboss – Joe C Jul 15 '18 at 08:58
  • Long story short: you need to assume that your program is going to crash with absolutely no grace whatsoever. Someone could pull the plug on your data centre, for example. Hazelcast was designed to deal with that (I doubt it has anything specifically for OOMs). – Joe C Jul 15 '18 at 09:00
  • https://stackoverflow.com/questions/7405046/can-i-auto-restart-tomcat-jvm-on-out-of-memory-exception/13119689#13119689 – Mikael Gueck Jul 15 '18 at 09:00
  • If you have something you can release, you can catch `OutOfMemoryError`, release it, and then see what happens. RMI does exactly this. However it isn't likely that you really have a valid continuation of the operation that has already failed. – user207421 Jul 15 '18 at 10:00

0 Answers0