Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart Tomcat from within itself

Tags:

java

tomcat

I would like to restart Tomcat automatically based on a certain condition. Basically I am operating within a 32 MB JVM and may run out of space. Hence I periodically check the status of free memory.

I would like to restart Tomcat from within itself if, say, the free memory percentage goes below 50%.

I know this is not a graceful approach. And I should be working more on fixing the memory leaks! But until I do that, I would like to know if there is a tactical solution to this problem.

like image 960
Sunil Shevante Avatar asked Feb 04 '26 22:02

Sunil Shevante


1 Answers

This might help you. Configure as per your need:

Batch/shell script for Tomcat start/stop:

cd tomcat_dir\bin
catalina stop
catalina start

Running batch file http://www.roseindia.net/answers/viewqa/Java-Beginners/5286-Running-Batch-files-in-java.html

For memory check http://viralpatel.net/blogs/getting-jvm-heap-size-used-memory-total-memory-using-java-runtime

Create Jar file and execute when OS starts and check at regular interval, say for 2 mins that heap size consumption is more ?

If more then run the above CallBatchFile.java process

like image 147
Sunil Gulabani Avatar answered Feb 06 '26 10:02

Sunil Gulabani