Share

Friday, May 13, 2016

How to set HeapMemory/JVM Arguments in Tomcat

Option 1:


Create the setenv.sh under CATALINA_HOME you can find the value of  CATALINA_HOME if you execute version.sh available under the installation_path/bin.

In general,  installation_path will be your CATALINA_HOME

[tomcat@localhost bin]$ ./version.sh
Using CATALINA_BASE:   /opt/tomcat/apache-tomcat-7.0.69
Using CATALINA_HOME:   /opt/tomcat/apache-tomcat-7.0.69
Using CATALINA_TMPDIR: /opt/tomcat/apache-tomcat-7.0.69/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/apache-tomcat-7.0.69/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-7.0.69/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.69
Server built:   Apr 11 2016 07:57:09 UTC
Server number:  7.0.69.0
OS Name:        Linux
OS Version:     2.6.32-504.el6.x86_64
Architecture:   amd64
JVM Version:    1.7.0_79-b15
JVM Vendor:     Oracle Corporation
 
[tomcat@localhost bin]$ pwd
/opt/tomcat/apache-tomcat-7.0.69/bin



If you have just installed the tomcat, you may not be having setenv.sh file available under the CATALINA_HOME/bin location. So you must create it.

Here we go.

I am creating a new file called setenv.sh under bin location and defining my JVM arguments.


[tomcat@localhost bin]$ cat > setenv.sh
JAVA_OPTS="-Xms1024m -Xmx1024m -Xss228k -XX:+UseParallelGC"

[tomcat@localhost bin]$ cat setenv.sh
JAVA_OPTS="-Xms1024m -Xmx1024m -Xss228k -XX:+UseParallelGC"

[tomcat@localhost bin]$ pwd
/opt/tomcat/apache-tomcat-7.0.69/bin

 

Option 2:

you can add these parameters in the very beginning of catalina.sh file.

#!/bin/sh
...
...  

......

#   LOGGING_MANAGER (Optional) Override Tomcat's logging manager
#                   Example (all one line)
#                   LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
# -----------------------------------------------------------------------------
JAVA_OPTS="-Xms1024m -Xmx1024m -Xss228k -XX:+UseParallelGC"

# OS specific support.  $var _must_ be set to either true or false
.

 

Verification:

Start the tomcat instance and verify.

you can verify the JVM arguments in two ways. 

1)  In catalina log you would be able to something like this.

INFO: Command line argument: -Xms1024m
May 13, 2016 10:34:46 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Xmx1024m
May 13, 2016 10:34:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Xss228k
May 13, 2016 10:34:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -XX:+UseParallelGC
 

2)  using ps command  you can find the JVM arguments

[tomcat@localhost ~]$ ps -eaf|grep -i java
tomcat    5944  3481  3 10:34 pts/0    00:00:05 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat/apache-tomcat-7.0.69/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms1024m -Xmx1024m -Xss228k -XX:+UseParallelGC -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/opt/tomcat/apache-tomcat-7.0.69/endorsed -classpath /opt/tomcat/apache-tomcat-7.0.69/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-7.0.69/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/apache-tomcat-7.0.69 -Dcatalina.home=/opt/tomcat/apache-tomcat-7.0.69 -Djava.io.tmpdir=/opt/tomcat/apache-tomcat-7.0.69/temp org.apache.catalina.startup.Bootstrap start
tomcat    6008  5988  0 10:37 pts/1    00:00:00 grep -i java
[tomcat@localhost ~]$

No comments :

Post a Comment