java.lang.OutOfMemoryError: Java heap space in tomcat7
Asked Answered
S

4

8

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.

Sarraceniaceous answered 10/3, 2014 at 4:56 Comment(0)
Y
16

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.

Younts answered 11/9, 2014 at 8:54 Comment(2)
Number 7 is (of course) depending on tomcat version (for me it's /etc/default/tomcat8).Declarative
This location is the Debian way of doing it; I would also look into the Xms option in the other answers.Zagreus
O
12

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.

Othelia answered 10/3, 2014 at 5:5 Comment(1)
If debian 7, usually /usr/share/tomcat7/bin/setenv.shHuynh
Z
5

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"
Zahavi answered 10/3, 2014 at 5:6 Comment(2)
I am using ubuntu. If i write this line in .bashrc file what it will do. please tell me. whether it is increase heap size or export. If export how can i find that file.Sarraceniaceous
I would not advise .bashrc. You want this configuration to be system wide, not specific to a user. On top of it, some Java instances (for example tomcat), run with their specific user, and as such, in that cases this configuration wont affect the Java instance.Zagreus
L
0
  1. Go to /bin and create a file named setenv.sh for Linux systems or setenv.bat for Windows.

  2. Inside the setenv file, use the following format to set the heap size using the following parameters:

-Linux:

export CATALINA_OPTS="-Xms4096M -Xmx4096M"
 

-Windows:

set CATALINA_OPTS=-Xms4096M -Xmx4096M
  1. Make sure both the values match for minimum and maximum.
  2. Save the file and restart Tomcat.
Lineman answered 4/3, 2021 at 19:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.