Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I auto restart tomcat jvm on out of memory exception

Tags:

I know that this is not "best practice" but I would like to know if I can auto restart tomcat if my deployed app throws an outofmemory exception

like image 469
Abe Avatar asked Sep 13 '11 16:09

Abe


People also ask

Can the JVM recover from an Outofmemoryerror without a restart?

In other words if an OOME is thrown in an application server (jboss/websphere/..) do I have to restart it? No you don't have to restart. But it is probably wise to, especially if you don't have a good / automated way of checking that the service is running correctly. The JVM will recover just fine.

Does Tomcat run on JVM?

Apache Tomcat is a Java servlet container, and is run on a Java Virtual Machine, or JVM. Tomcat utilizes the Java servlet specification to execute servlets generated by requests, often with the help of JSP pages, allowing dynamic content to be generated much more efficiently than with a CGI script.

What is Tomcat heap memory?

The Tomcat server is run within a Java Virtual Machine (JVM). This JVM that controls the amount of memory available to LabKey Server. LabKey recommends that the Tomcat web application be configured to have a maximum Java Heap size of at least 2GB for a test server, and at least 4GB for a production server.

What is ExitOnOutOfMemoryError?

ExitOnOutOfMemoryError. When you enable this option, the JVM exits on the first occurrence of an out-of-memory error. It can be used if you prefer restarting an instance of the JVM rather than handling out of memory errors. Format.


1 Answers

You can try to use the OnOutOfMemoryError JVM option

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

It is also possible to generate the heap dump for later analysis:

-XX:+HeapDumpOnOutOfMemoryError 

Be careful with combining these two options. If you force killing the process in "tomcat-restart" the heap dump might not be complete.

like image 71
Dan Avatar answered Oct 09 '22 16:10

Dan