You can use this Oracle Hotspot option to run commands when a java.lang.OutOfMemoryError is thrown. This option is recognized by OpenJ9 and provided for compatibility.



where <command_string> is a command or list of commands to run when a java.lang.OutOfMemoryError occurs.

For example, the following command specifies that the java -version command is run if the Test application throws a java.lang.OutOfMemoryError exception:

java -XX:OnOutOfMemoryError="java -version" Test

If you want to run multiple commands, use semicolons to separate them within <command_string>. For example:

-XX:OnOutOfMemoryError="<java_path> <java_program>; cat file.txt"

The -XX:OnOutOfMemoryError option is equivalent to the following -Xdump option:


For more information, see -Xdump.