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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With