Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart tomcat automatically when it gets outofmemory error

How can I configure Tomcat to automatically restart when get an out of memory [OOME] error.

As i think

-XX:OnOutOfMemoryError="/yourscripts/tomcat-restart"

But not sure here "yourscripts" stand for what directory?

like image 776
Ajain Avatar asked Mar 09 '26 09:03

Ajain


1 Answers

The value you provide to -XX:OnOutOfMemoryError must be the fully qualified path to an executable (can be executable script). That script must return basically immediately so that the jvm can continue and shutdown. So it needs to attempt to stop and start tomcat in the background. This may result in effectively 2 scripts:

Script 1:

#!/bin/bash
script2.sh &

Script 2:

# stop tomcat
# make sure it is dead (kill "zombie" process if necessary)
# start tomcat

The -XX:OnOutOfMemoryError shoudl point to script 1.

like image 50
Brett Okken Avatar answered Mar 10 '26 23:03

Brett Okken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!