Can I auto restart tomcat jvm on out of memory exception

后端 未结 7 1652
北海茫月
北海茫月 2021-01-31 05:12

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

7条回答
  •  情话喂你
    2021-01-31 05:45

    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.

提交回复
热议问题