Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.OutOfMemoryError: Java heap space in tomcat7

Tags:

java

tomcat7

I am getting this error in tomcat server.

Exception in thread "http-bio-8080-exec-17" 
Exception in thread "http-bio-8080-exec-2"
Exception in thread "http-bio-8080-exec-15" 
Exception in thread "http-bio-8080-exec-20"
Exception in thread "http-bio-8080-exec-18" 
java.lang.OutOfMemoryError: Java heap space.

I have seen MAT but how do I generate the .hprof file in my Tomcat server.

Thank you.

like image 908
prabhu Avatar asked Mar 10 '14 04:03

prabhu


3 Answers

to remove the error edit the file

/etc/default/tomcat7   

replace with:

JAVA_OPTS="-Djava.awt.headless=true -Xmx1280m -XX:+UseConcMarkSweepGC"

Then restart the web server.

Xmx is the new maximum size of memory and it should be affordable by your machine.

like image 173
Jobin Avatar answered Oct 07 '22 12:10

Jobin


add this line to /path/to/tomcat/bin/setenv.sh (if doesn't exist create it) :

CATALINA_OPTS="$CATALINA_OPTS -server -Xms256m -Xmx1024m"

this increases tomcat's heap size to 1024MB.

like image 44
Taher Khorshidi Avatar answered Oct 07 '22 13:10

Taher Khorshidi


Solution as per your OS:

if Ubuntu:

open .bashrc file available in user home folder (it is hidden) and Add or Edit one line among last 2-3 lines:

export CATALINA_OPTS="-Xms512m -Xmx1024m"

else Windows:

In your environment variables add/edit

CATALINA_OPTS = "-Xms512m -Xmx1024m"
like image 5
ravi.patel Avatar answered Oct 07 '22 12:10

ravi.patel