found that the java.lang.Outofmemoryerror: Java heap space error may be being caused by Try/catch with catch with nothing in the code, similar to the following:
Surely the cause of the error java.lang.OutOfMemoryError: Java heap space
is not this.
I would like to know how it is possible to treat this WITHOUT interrupting the code (showing a screen or error message) and WITHOUT changing the operation of the application.
This is also not possible. The error java.lang.OutOfMemoryError: Java heap space
occurs when your application no longer has memory available in heap. Having memory available in heap is essential for your Java application to work, there is no way around it at runtime.
What you need to do is identify in your code the point (or points) that must be consuming a lot of memory and do the proper optimization. You can also choose to increase the memory size heap available for your application with the argument Xms
, if your application "naturally" consumes a lot of memory (and is not consuming a lot of memory due to programming failure).
For example, the -Xmx1024m
up to 1024MB of the available heap area:
export JVM_ARGS="-Xmx1024m"
The application of the option -Xmx
will vary conform the application, because this option can be an argument of the execution of a jar, can be inside the application server, can be in the environment variable (as in the example above), etc. It will depend on how is starting your current application.