The startup scripts of tomcat will run a setenv.sh file if it exists. Create it (in the tomcat bin/ ) directory and write your customization there, e.g. that file can just contain the line:
export JAVA_OPTS="-Xms756m -Xmx756m -Xss128m -Xmn512m"
Answer from nos on Stack OverflowThe startup scripts of tomcat will run a setenv.sh file if it exists. Create it (in the tomcat bin/ ) directory and write your customization there, e.g. that file can just contain the line:
export JAVA_OPTS="-Xms756m -Xmx756m -Xss128m -Xmn512m"
when you do it from the command line, the params are not written anywhere. They exist only for your current bash session.
Put export JAVA_OPTS="..." in your ~/.bashrc or ~/.bash_profile files to persist them. If you are on OS X you will have to source the .bashrc file from .profile.
You have pretty much nailed it except that these options are picked up even if you start JVM in-process via a library call.
The fact that _JAVA_OPTIONS is not documented suggests that it is not recommended to use this variable, and I've actually seen people abuse it by setting it in their ~/.bashrc. However, if you want to get to the bottom of this problem, you can check the source of Oracle HotSpot VM (e.g. in OpenJDK7).
You should also remember that there is no guarantee other VMs have or will continue to have support for undocumented variables.
UPDATE 2015-08-04: To save five minutes for folks coming from search engines, _JAVA_OPTIONS trumps command-line arguments, which in turn trump JAVA_TOOL_OPTIONS.
There is one more difference: _JAVA_OPTIONS is Oracle specific. IBM JVM is using IBM_JAVA_OPTIONS instead. This was probably done to be able to define machine-specific options without collisions. JAVA_TOOL_OPTIONS is recognized by all VMs.
JAVA_OPTS is the standard environment variable that some servers and other java apps append to the call that executes the java command.
For example in tomcat if you define JAVA_OPTS='-Xmx1024m', the startup script will execute java org.apache.tomcat.Servert -Xmx1024m
If you are running in Linux/OSX, you can set the JAVA_OPTS, right before you call the startup script by doing
JAVA_OPTS='-Djava.awt.headless=true'
This will only last as long as the console is open. To make it more permanent you can add it to your ~/.profile or ~/.bashrc file.
Just figured it out in Oracle Java the environmental variable is called: JAVA_TOOL_OPTIONS
rather than JAVA_OPTS
Hmm, deleted the whole file and recreated it, and now it works..... Now using this style
export JAVA_OPTS="$JAVA_OPTS\
-server\
-Xms704m\
-Xmx704m\
-XX:OnOutOfMemoryError=/usr/share/scripts/on_server_crash.sh\
-XX:+HeapDumpOnOutOfMemoryError\
-XX:HeapDumpPath=/var/log/tomcat7\
-XX:MaxPermSize=128m\
-XX:MaxNewSize=256m\
-XX:NewSize=256m\
-XX:SurvivorRatio=12\
-XX:MaxTenuringThreshold=0\
-XX:+UseConcMarkSweepGC\
-XX:+CMSIncrementalMode\
-XX:+CMSIncrementalPacing\
-XX:+CMSClassUnloadingEnabled\
-XX:+CMSPermGenSweepingEnabled\
-XX:+DisableExplicitGC\
-XX:+UseParNewGC\
-XX:+UseTLAB\
-Djava.awt.headless=true\
-javaagent:$NR_JAR\
-Dnewrelic. environment=production"
You'd be better off with:
JAVA_OPTS="$JAVA_OPTS -server "
JAVA_OPTS="$JAVA_OPTS -Xms512m -Xmx512m"
export JAVA_OPTS