OnOutOfMemoryError 옵션을 이용할 경우 OutOfMemroy 발생 이후에 특정 동작을 지정할 수 있다.

톰캣 catalina.sh 파일의 CATALINA_OPTS 옵션에 "-XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError"을 이용하면 된다.

 

[/bin/setenv.sh 파일 생성]

 

-------------------------------------------------------------------------------------------------------------------------

예1 : OOM 발생시 톰캣을 재시작하는 쉘 스크립트를 실행

CATALINA_OPTS="-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/usr/local/tomcat9/logs -XX:OnOutOfMemoryError=/home/test/tomcatRestart.sh" 


예2 : OOM 발생시 톰캣을 재시작하는 쉘 스크립트를 실행
CATALINA_OPTS="-Djava.awt.headless=true -server -Xms256m -Xmx1024m -XX:MaxPermSize=128m -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=/home/test/tomcatRestart.sh"

예3 : OOM 발생시 해당 톰캣을 강제로 중지.
CATALINA_OPTS="-Djava.awt.headless=true -server -Xms256m -Xmx1024m -XX:MaxPermSize=128m -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError='kill -9 %p'"

 

-------------------------------------------------------------------------------------------------------------------
CATALINA_OPTS="-server -Xmx2g -Xms2g -XX:PermSize=512m -XX:MaxPermSize=512m -XX:+UseParallelOldGC -Dfile.encoding=UTF-8" 
CATALINA_OPTS="$CATALINA_OPTS -verbosegc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails"
-------------------------------------------------------------------------------------------------------------------

 

* 톰캣 재시작 스크립트(tomcatRestart.sh)

======================================================================

#!/bin/sh
 
export JAVA_HOME=/usr/local/java
export PATH="$PATH:$JAVA_HOME/bin"
export CATALINA_HOME=/usr/local/tomcat7
  
# 톰캣 재시작
/usr/local/tomcat7/bin/shutdown.sh
 
sleep 10
 
/usr/local/tomcat7/bin/startup.sh
======================================================================

shutdown.sh를 실행시킬때에는 간혹가다 톰캣이 중지가 안되는경우가 있으므로  shutdown.sh에 force 옵션등을 추가

 

[참고] https://fruitdev.tistory.com/204?category=558549 

 

+ Recent posts