Memory leaks occur. However, I would like to avoid being notified that the site has gone down during a long vacation, so I investigated the method.
Example: Create a file restartTomcat.sh like ↓ and place it in an appropriate location (/ usr / local / tomcat / bin, etc.).
restartTomcat.sh
#!/bin/bash
#Restart tomcat (example) If there is a command you want to execute other than restart, write it together. Like skipping emails.
systemctl restart tomcat.service
Add the following option to the environment variable CATALINA_OPTS to specify the command to execute on OutOfMemoryError.
One way to specify the tomcat jvm option is If you put a file called "setenv.sh" in / usr / local / tomcat / bin, it will be read from catalina.sh when Tomcat starts.
Example:
setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -XX:OnOutOfMemoryError=\"/usr/local/tomcat/bin/restartTomcat.sh\""
This will run restartTomcat.sh on OutOfMemoryError.
If you also want to output HeapDump, add the following two options to the environment variable CATALINA_OPTS.
--- XX: + HeapDumpOnOutOfMemoryError (HeapDump is output at the time of OutOfMemoryError.) --- XX: HeapDumpPath (Specify the output destination of HeapDump above.)
Example:
setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
export CATALINA_OPTS="$CATALINA_OPTS -XX:HeapDumpPath=/usr/local/tomcat/logs"
export CATALINA_OPTS="$CATALINA_OPTS -XX:OnOutOfMemoryError=\"/usr/local/tomcat/bin/restartTomcat.sh\""