The command parameter may contain the special sequence %p, which is replaced by the process identifier of the JVM process.
The -XX:OnOutOfMemoryError option allows an operator to specify a command or sequence of commands to execute when the JVM runs out of memory. This occurs when an OutOfMemoryError exception is first thrown.
This could be used for example to generate additional data that could help to diagnose a memory leak. Alternatively it could be used to alert the operator so that corrective action can be taken (e.g. restarting the process).
The command string can be either a single command, or multiple commands separated by semicolons. If the command string contains one or more instances of the special sequence %p then it shall be replaced with the identifier of the Java process. If the command string contains spaces then it must be surrounded by quotation marks.
java -XX:OnOutOfMemoryError="echo 'Process %p has run out of memory.' \
| mail -s 'Java OOM' email@example.com"
This sends an email to firstname.lastname@example.org to alert them of the out-of-memory
java -XX:OnOutOfMemoryError="userdump.exe %p"
This runs the userdump.exe utility to generate a dump file (assuming that
userdump.exe is available from the PATH environment variable).
The default value of -XX:OnOutOfMemoryError is empty, i.e. no action is performed when an out-of-memory condition is first reached.
Arguments Related to -XX:OnOutOfMemoryError:
TODO: link to -XX:OnError
If you have additional comments, interesting experiences or even point of disagreement with this JVM argument description, please leave a comment. Your
insights will help the entire 10+ million java developer community to develop
one standard source of documentation for all the JVM arguments.
Edit your Comment