Hasan Zia
Hasan Zia

Reputation: 11

Need to know the root cause of "OutOfMemoryError : Java Heap Space"

I am getting following error on linux machine.

Exception in thread "http-8080-Processor17" java.lang.OutOfMemoryError:Java Heap Space

and one of the port 8080 is getting in close wait every now and then.

Kindly suggest root cause of the issue.

Upvotes: 1

Views: 3304

Answers (3)

Dimos
Dimos

Reputation: 8908

In order to find the reason behind the memory exception, you can take a thread dump of your application. To get a thread dump, execute the command:

kill -3 <process_id>

where <process_id> is the pid of your process.You can find it with :

ps aux | grep java

or any other tool available. The thread dump will be sent to the standard output stream, without terminating the process. So, you can analyse the logs. You can also use the following JVM option:

-XX:OnOutOfMemoryError="kill -3 %p"

to automatically generate thread dumps of your process at every OutOfMemory error.

Upvotes: 3

Animesh Agrawal
Animesh Agrawal

Reputation: 161

You can Have finite heap no matter what platform you are running whether it is Linux or Windows or any other platform. Java Allocate limited amount of Memory to run a program. this memory space can be divided in two regions.

  1. Heap : Stores the objects.
  2. PermSpace : Stores meta data of user class.

You can initialize the heap and PermSpace by passing arguments "-XX:MaxPermSize" You can initialize heap size by passing arguments "-Xmx" if you are not initializing JVM will allocate default memory to your application.

You can check Use Java Memory Profiler to check which part of your program is using more space in memory.

Upvotes: 1

RahulArackal
RahulArackal

Reputation: 954

java.lang.OutOfMemoryError:Java Heap Space : Usually happens due to lack of system memory(for the JVM), sometimes it can also happen due to memory leaks(programming).

JVM throws "OutOfMemoryError" when it ran out of java heap memory

To solve OutOfMemoryError: java heap Space, (easy way)

increase heap size by setting JVM arguments "-Xms" and -Xmx" - Minimum and Maximum Heap Size

check the current value and increase it like "-Xmx1024M"

If its not solved then it must be due to memory leak(idk more about how to fix memory leak) For better understanding refer : Java Heap Space

Upvotes: 0

Related Questions