By default Tomcat server sets its own memory heap size 64MB but its not
enough for run your application, so we can set size by CATALINA_OPTS or
JAVA_OPTS,
-Xmx set Maximum Java Heap Size
-Xms set Initial Java Heap Size
-Xms set Initial Java Heap Size
Option 1:
Open the catalina.sh script file under $CATALINA_HOME/bin/catalina.sh
directory assign it,
1
2
| export CATALINA_OPTS= "-Xms128M -Xmx512M" |
or simply export,
1
2
| export CATALINA_OPTS= "-Xms128M -Xmx512MB" |
The heap size has been set to Minumum 128MB and maximum 512MB
Option 2:
$CATALINA_HOME/bin/setenv.sh
Another option is create a setenv.sh file and add below line,
1
2
| export CATALINA_OPTS= "${CATALINA_OPTS}
-Djava.awt.headless=true
-Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true
-Dmail.mime.decodeparameters=true -Xms128m -Xmx512m -XX:PermSize=256m
-XX:MaxPermSize=950m -XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled" |
or
1
| export CATALINA_OPTS= "-Xms128M -Xmx512MB" |
You might restart tomcat server,
# pkill -9 java
# /usr/local/apache-tomcat/bin/startup.sh
# ps aux | grep java
# /usr/local/apache-tomcat/bin/startup.sh
# ps aux | grep java
1
2
3
| root 9447 1.1 13.2 2127844 543868 ? Sl 17:20 3:38 /usr/java/jdk1 .7.0 /bin/java -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config. file = /usr/local/tomcat7/conf/logging .properties -Djava.awt.headless= true -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER= true -Dmail.mime.decodeparameters= true -Xms128m -Xmx512m -XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -Djava.endorsed. dirs = /usr/local/tomcat7/endorsed -classpath : /usr/local/tomcat6/bin/bootstrap .jar: /usr/local/tomcat7/bin/commons-logging-api .jar -Dcatalina.base= /usr/local/tomcat7 -Dcatalina.home= /usr/local/tomcat7 -Djava.io.tmpdir= /usr/local/tomcat6/temp org.apache.catalina.startup.Bootstrap start root 12761 0.0 0.0 103244 868 pts /0 S+ 22:24 0:00 grep java |
or can use netstat command,
# netstat -anp | grep java
1
2
3
4
5
6
7
| tcp 0 0 :::8009 :::* LISTEN 9447 /java tcp 0 0 :::8080 :::* LISTEN 9447 /java tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 9447 /java tcp 0 0 ::ffff:127.0.0.1:35334 ::ffff:127.0.0.1:3306 ESTABLISHED 9447 /java tcp 0 0 ::ffff:127.0.0.1:56156 ::ffff:127.0.0.1:3306 ESTABLISHED 9447 /java unix 2 [ ] STREAM CONNECTED 113825 9447 /java |
Windows Server:
To set in windows operating system, Create a setenv.bat file and add the below line,
1
| export JAVA_OPTS= "-server -Xmx512m" |
or
1
| set JAVA_OPTS= "-Xms256m -Xmx512m" |
Error:
If you may get an error java.lang.OutOfMemoryError: PermGen space in both windows or linux system,
Configure the MaxPermSize value in setenv.sh or catalina.sh like,
1
2
| export JAVA_OPTS= "-Xms256m -Xmx512m -XX:MaxPermSize=128m" |
If you have changed any configuration might restart tomcat server.
No comments:
Post a Comment