Try/Catch: java.lang.Outofmemoryerror: Java heap space

Asked

Viewed 475 times

0

I have a very serious problem in my web application, and after a lot of research, I found that the error

java.lang.Outofmemoryerror: Java heap space

Could be being caused by try/catch with catch with nothing in the code, similar to the following:

try {
    //FAZ ALGUMA COISA
} catch (Exception e) {
}

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.

Or if you have any idea what else might cause this problem and what might solve it.

2 answers

1

It is not to treat this type of error, this is the most serious error that can happen with its application and it is intractable in it, this occurs by serious programming errors occurring even in other places or by accumulation of errors. You have to figure out what’s causing this, but the place that makes this mistake is just a symptom, there’s no point in trying to do something there, there’s a source.

The mistake is never caused by what you found in your research. What I can see is that you’re doing random things, and that’s gonna make it harder to find the problem. To be quite honest I think you will have to hire someone who is able to find the mistake. It can be many and be very complicated to solve.

What is certain is that we have no way to help in the specific problems, only guide you on the real solution.

0

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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.