Modify Tomcat VM parameters in Linux
Unfeasible Method
Initially, I directly modified catalina. sh and added the JAVA_OPTS variable
-server -Xms1G -Xmx1G -XX:+UserG1GC
It seems that there is no problem at first, but after the server runs for a few days, it finds that the shutdown. sh command cannot be executed to close tomcat. The error message is as follows:
# root@iZ94hjppdqzZ:~/projects/taolijie# cat hs_err_pid5519.log # There is insufficient memory for the Java Runtime Environment to continue.# Native memory allocation (mmap) failed to map 1073741824 bytes for committing reserved memory.# Possible reasons:# The system is out of physical RAM or swap space# In 32 bit mode, the process size limit was hit# Possible solutions:# Reduce memory load on the system# Increase physical memory or swap space# Check if swap backing store is full# Use 64 bit Java on a 64 bit OS# Decrease Java heap size (-Xmx/-Xms)# Decrease number of Java threads# Decrease Java thread stack sizes (-Xss)# Set larger code cache with -XX:ReservedCodeCacheSize=# This output file may be truncated or incomplete.## Out of Memory Error (os_linux.cpp:2673), pid=5519, tid=3061726064## JRE version: (8.0_45-b14) (build )# Java VM: Java HotSpot(TM) Server VM (25.45-b02 mixed mode linux-x86 )# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again#
Shut down tomcat and request 1 GB Of Memory. At that time, the server had MB Of Memory left, so Out Of Memory. Check shutdown. sh and find that it still calls catalina. sh, but passes in a stop parameter. The catalina. sh command is executed.
org.apache.catalina.startup.Bootstrap stop
To send a close message to tomcat. As we have set JAVA_OPTS to use 1 GB Of heap, JVM will apply more than 1 GB Of Memory to the system when executing this class, which directly leads to Out Of Memory.
Feasible Method
Add the following in the second line of catalina. sh:
CATALINA_OPTS="$CATALINA_OPTS -server -Xms1G -Xmx1G -XX:+UseG1GC"
These VM parameters will only be applied to catalina rather than all Tomcat processes.