XX:OnOutOfMemoryError on setenv.sh

1.8k Views Asked by At

i want to set a script which will restart the server automatically.

And i write the following code to setenv.sh file

JAVA_OPTS="$JAVA_OPTS -XX:OnOutOfMemoryError=/usr/local/apache-tomcat-5.5.30/bin/shutdown.sh;/usr/local/apache-tomcat-5.5.30/bin/startup.sh;"

It not working properly. I am using tomcat 5.

2

There are 2 best solutions below

2
On

To answer your question - I don't think the error handler can run several commands. If you want to do this, then write a small restart script and run your custom script.

However, I would think about this again. Not every OutOfMemoryError means the server should be restarted automatically. You'd better to get a notification and then profile the server to get the cause of the OOME, so you can get rid of it.

P.S Any reason to use the old tomcat 5.5? tomcat 7 is quite mature.

0
On

Use CATALINA_OPTS instead

CATALINA_OPTS="${CATALINA_OPTS} -XX:OnOutOfMemoryError=\"/bin/sleep 30;/bin/kill %p; /bin/sleep 60; /bin/kill -9 %p\""