Do not get stuck in #Java with Out of Memory threads.

By | February 28, 2018

In a JVM environment sometimes a thread can end up with an “OutOfMemoryError” exception. If this occurs we have a problem and most of the times this is so bad that we should no longer continue.
The last thing you want in this case is to get stuck in a limbo state where your java program no longer acting properly due to lack of memory.
The most important JVM implementations started to be aware about this case and offer features that can be used to get out of this limbo state.

On IBM implementation of JVM we have the concept of dump agents.

Dump agents are set up during JVM initialization. They enable you to use events occurring within the JVM, such as Garbage Collection, thread start, or JVM termination, to initiate one of four types of dump or to launch an external tool. The -Xdump option allows you add and remove dump agents for various JVM events, update default dump settings (such as the dump name), and limit the number of dumps that are produced.

See link for details.

To activate this feature add to the command line used to start the JVM:


where /home/was/ is a script that shuts down our application.

Oracle JVM
On Oracle implementation of JVM we have two additional flags added in the latest JDK8 and JDK9 releases.

Two new JVM flags have been added:

When you enable this option, the JVM exits on the first occurrence of an out-of-memory error. It can be used if you prefer restarting an instance of the JVM rather than handling out of memory errors.

If this option is enabled, when an out-of-memory error occurs, the JVM crashes and produces text and binary crash files (if core files are enabled).

To activate this feature add to the command line used to start the JVM:


This will ensure that in case of an OOM the Java process will exit.

Contribute to this site maintenance !

This is a self hosted site, on own hardware and Internet connection. The old, down to earth way 🙂. If you think that you found something useful here please contribute. Choose the form below (default 1 EUR) or donate using Bitcoin (default 0.0001 BTC) using the QR code. Thank you !


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.