Profile Image
vishnupriya

What is Java On-Out-of-Memory Command: -XX:OnOutOfMemoryError?

What is Java On-Out-of-Memory Command: -XX:OnOutOfMemoryError? Have you used this JVM argument before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvm-argument

  • xx-onoutofmemoryerror

  • x-onoutofmemoryerror

  • Java On-Out-of-Memory Command

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky

Usage:

 

• -XX:OnOutOfMemoryError=<command>

 

The command parameter may contain the special sequence %p, which is replaced by the process identifier of the JVM process.

 

Description:

 

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.

 

Examples:


Linux/MacOS example:
java -XX:OnOutOfMemoryError="echo 'Process %p has run out of memory.' \
| mail -s 'Java OOM' operator@acme.com"
This sends an email to operator@acme.com to alert them of the out-of-memory
condition.


Windows example:
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).

 

Default Value:


The default value of -XX:OnOutOfMemoryError is empty, i.e. no action is performed when an out-of-memory condition is first reached.


Errors:


None

 

Arguments Related to -XX:OnOutOfMemoryError:


TODO: link to -XX:OnError


Related Posts


None


NOTE:


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.

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvm-argument

  • xx-onoutofmemoryerror

  • x-onoutofmemoryerror

  • Java On-Out-of-Memory Command