In our java application, we need to send email in case the application goes out of memory and recovers from it by its own. To do so, we need a callback kind of thing that should be called once the JVM recovered from OOM. Is there such a callback in Java?
Asked
Active
Viewed 76 times
1
-
duplicate https://stackoverflow.com/questions/3058198/can-the-jvm-recover-from-an-outofmemoryerror-without-a-restart – Marcin Wasiluk Nov 28 '22 at 08:02
-
What does "recovered" mean in this context? – tgdavies Nov 28 '22 at 08:40
-
@tgdavies 'recovered' means became responsive again. After recovery the JVM will function normally. – Kather Nov 28 '22 at 09:38
-
@MarcinWasiluk Not exactly duplicate. – Kather Nov 28 '22 at 09:38
-
As the answer to that question says, you are better off forcing your app to exit (and be restarted by your environment) than to let it keep running. – tgdavies Nov 28 '22 at 10:51
1 Answers
1
Use -XX:OnOutOfMemoryError=<command>
JVM option.
If you need more flexible error handling within the Java process itself, look at ResourceExhausted
JVMTI callback.

apangin
- 92,924
- 10
- 193
- 247