Profile Image
vishnupriya

What is JVM startup parameter: -XX:[+|-]ExitOnOutOfMemoryError?

What is JVM startup parameter: -XX:[+|-]ExitOnOutOfMemoryError? Have you used this JVM arguement before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvmargument

  • xx-exitonoutofmemoryerror

  • x-exitonoutofmemoryerror

  • JVM startup parameter

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky

Usage:                                                    

 

Exist the program if an out of memory exception is thrown.

 

Since:

 

Starting from JDK 8.

 

Syntax:

 

java -XX:[+|-]ExitOnOutOfMemoryError MainClass

 

Examples:

  • To enable the JVM to exit on the out of memory exception: java -XX:+exitOnOutOfMemory MainClass
  • To disable the JVM to exit on an out of memory exception: java -XX:-exitOnOutOfMemory MainClass

 

Description:

 

This option makes JVM exit on the first occurrence of an out of memory exception. It can be used if you prefer restarting an instance of JVM rather than handling out of memory errors. They are many causes of an out of memory:

 

  • Java heap space
    • This error will be thrown when the application tries to add more data into heap space while there is no space left.
  • GC overhead limit exceeded
    • This error is thrown when GC tried to free memory but was unable to do so.
  • Metaspace/Compressed class space
    • When there are bug classes or too many classes are being loaded to the metaspace of the application, this error is thrown.
  • Unable to create new native thread
    • Whenever the JVM can not create a new native thread, this error will be thrown.
  • Out of swap space?
    • This error is thrown when there is insufficient swap space or another running process is consuming all memory.
  • Requested array size exceeds VM limit
    • When the application is trying to reserve an array larger than the JVM can support, this error is thrown.

Default Value:

 

By default, it’s disabled.

 

Errors:

 

None.

 

Arguments related:

 

CrashOnOutOfMemoryError, ExitOnOutOfMemoryErrorExitCode and HeapDumpOnOutOfMemoryError.

 

Related Posts:

 

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvmargument

  • xx-exitonoutofmemoryerror

  • x-exitonoutofmemoryerror

  • JVM startup parameter