Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Caused by: java.lang.OutOfMemoryError: Java heap space

MY GOAL:

I want run my application for 1000 users.

NOW

I am trying to run for 100 user. During application run, I'd like to do some process for each user that will take a minimum of one hour per user, so I'm using one thread per user.

ERROR

Caused by: java.lang.OutOfMemoryError: Java heap space

I've tried to figure out what this means, but I'm not really sure how to resolve it.

Can anybody help me?

like image 668
Ganesa Vijayakumar Avatar asked Aug 06 '12 07:08

Ganesa Vijayakumar


People also ask

What causes Java Lang OutOfMemoryError heap space?

lang. OutOfMemoryError exception. Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further.

How do you deal with Java Lang OutOfMemoryError Java heap space error?

Easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options -Xmx512M , this will immediately solve your OutOfMemoryError.

How do I fix a heap space error?

The java. lang. OutOfMemoryError: Java heap space error occurs when it attempts to add more data into the heap space area, but there is not enough room for it. The solution to fix this problem is to increase the heap space(Default value maybe 128 MB).

How do you stop Java Lang OutOfMemoryError?

As explained in the above paragraph this OutOfMemory error in java comes when the Permanent generation of heap is filled up. To fix this OutOfMemoryError in Java, you need to increase the heap size of the Perm space by using the JVM option "-XX: MaxPermSize".


1 Answers

This error means that your program needs more memory than your JVM allowed it to use!

Therefore you pretty much have two options:

  1. Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m)
  2. Modify your program so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program

As Peter Lawrey pointed out, using a profiler to see what your program is doing in such situations is generally a good idea.

like image 110
Jean Logeart Avatar answered Sep 22 '22 08:09

Jean Logeart