Skip to content

Instantly share code, notes, and snippets.

Created May 23, 2011 00:07
Show Gist options
  • Save terrancesnyder/986029 to your computer and use it in GitHub Desktop.
Save terrancesnyder/986029 to your computer and use it in GitHub Desktop.
./ - example with defaults set for minimal time spent in garbage collection
#! /bin/sh
# ==================================================================
# ______ __ _____
# /_ __/___ ____ ___ _________ _/ /_ /__ /
# / / / __ \/ __ `__ \/ ___/ __ `/ __/ / /
# / / / /_/ / / / / / / /__/ /_/ / /_ / /
#/_/ \____/_/ /_/ /_/\___/\__,_/\__/ /_/
# Multi-instance Apache Tomcat installation with a focus
# on best-practices as defined by Apache, SpringSource, and MuleSoft
# and enterprise use with large-scale deployments.
# Credits:
# Google -> Couldn't survive without it
# -> Community support
# SpringSource -> Specifically best-practices and seminars (Expert Series)
# Based On:
# Created By: Terrance A. Snyder
# URL:,
# Best Practice Documentation:
# Looking for the latest version?
# github @
# ==================================================================
# discourage address map swapping by setting Xms and Xmx to the same value
# Increase maximum perm size for web base applications to 4x the default amount
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=256m"
# Reset the default stack size for threads to a lower value (by 1/10th original)
# By default this can be anywhere between 512k -> 1024k depending on x32 or x64
# bit Java version.
# Oracle Java as default, uses the serial garbage collector on the
# Full Tenured heap. The Young space is collected in parallel, but the
# Tenured is not. This means that at a time of load if a full collection
# event occurs, since the event is a 'stop-the-world' serial event then
# all application threads other than the garbage collector thread are
# taken off the CPU. This can have severe consequences if requests continue
# to accrue during these 'outage' periods. (specifically webservices, webapps)
# [Also enables adaptive sizing automatically]
# This is interpreted as a hint to the garbage collector that pause times
# of <nnn> milliseconds or less are desired. The garbage collector will
# adjust the Java heap size and other garbage collection related parameters
# in an attempt to keep garbage collection pauses shorter than <nnn> milliseconds.
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxGCPauseMillis=1500"
# A hint to the virtual machine that it.s desirable that not more than:
# 1 / (1 + GCTimeRation) of the application execution time be spent in
# the garbage collector.
# The hotspot server JVM has specific code-path optimizations
# which yield an approximate 10% gain over the client version.
# Disable remote (distributed) garbage collection by Java clients
# and remove ability for applications to call explicit GC collection
export CATALINA_OPTS="$CATALINA_OPTS -XX:+DisableExplicitGC"
# Check for application specific parameters at startup
if [ -r "$CATALINA_BASE/bin/" ]; then
echo "Using CATALINA_OPTS:"
for arg in $CATALINA_OPTS
echo ">> " $arg
echo ""
echo "Using JAVA_OPTS:"
for arg in $JAVA_OPTS
echo ">> " $arg
echo "_______________________________________________"
echo ""
Copy link


Copy link

Thanks .. Really very helpful..

Copy link

nickk75 commented May 18, 2016

Thanks for the knowledge sharing dude, much appreciated

Copy link

wimco commented Jun 21, 2016

Hi Guys i have installed Alfresco community 5.0.e on Ubuntu 14.04 LTS and i cant find file. What can I do i want to run javascript debugger

Copy link


Copy link

The various CATALINA_OPTS such as -Xms , Xmx, XX:MaxPermSize seem to be independant of physical RAM.
Is it right ?
What are the default values (for Tomcat 7) ?

Copy link

It does not work for me
Creating with just export CATALINA_OPTS="$CATALINA_OPTS -Xmx512m" in it crashes tomcat7 on start.
$CATALINA_OPTS is not defined in my standard tomcat7 installation on Debian Jessie.
Should I define it somewhere ?

Copy link

thank you so much

Copy link

Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment