Can I auto restart tomcat jvm on out of memory exception

后端 未结 7 1640
北海茫月
北海茫月 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:37

    Unfortunately when you kill the java process. Your script will keep a reference to the tomcat ports 8080 8005 8009 and you will not be able to start it again from the same script. The only way it works for me is:

    -XX:OnOutOfMemoryError="kill -9 %p" and then another cron or monit or something similar to ensure you have the tomcat running again.

    %p is actually the JVM pid , something the JVM provides for you.

提交回复
热议问题