Search code examples
javatomcatgarbage-collectionconcurrent-mark-sweep

How to use JVM parameters for web application running on tomcat, on linux machine


I want to use a different garbage collector than the default Parallel GC for my web application when deployed on my production server, which will be on linux.

Say for an example i want to use Concurrent Mark Sweep GC for the application.

Now i have read that we can use this by adding -XX:+UseConcMarkSweepGC and various other JVM parameters to fine tune it.

So while packaging my war using maven i include this extra JVM parameters. example:

mvn clean package -Dgwt.extraJvmArgs="-Xms2048m -Xmx2048m -XX:PermSize=512M -XX:MaxPermSize=512M -XX:+UseConcMarkSweepGC" 

The war is packaged, i deploy it on my tomcat server which is running on linux environment.

Note i package this war on a windows machine then deploy the war in linux machine using putty and winscp

What i don't understand is how will this ensure that CMS GC is running? I mean shouldn't i include these changes where my application is running?

Or including these JVM parameters while packaging the was is good enough.

Same goes if i want to include various other JVM parameters, including while packaging the war is good to go or we need to include these some where else too?

Please explain.


Solution

  • Add these parameters in [TOMCAT_HOME]/bin/catalina.sh with JAVA_OPTS

    JAVA_OPTS=-Dgwt.extraJvmArgs="-Xms2048m -Xmx2048m -XX:PermSize=512M -XX:MaxPermSize=512M -XX:+UseConcMarkSweepGC"
    

    It doesn't have any effect on providing these while packaging the war file.