简体   繁体   English

当出现内存错误时自动重启tomcat

[英]Restart tomcat automatically when it gets outofmemory error

How can I configure Tomcat to automatically restart when get an out of memory [OOME] error. 如何在出现内存不足[OOME]错误时将Tomcat配置为自动重启。

As i think 我想

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

But not sure here "yourscripts" stand for what directory? 但不确定这里的“yourscripts”代表什么目录?

The value you provide to -XX:OnOutOfMemoryError must be the fully qualified path to an executable (can be executable script). 您为-XX:OnOutOfMemoryError提供的值-XX:OnOutOfMemoryError必须是可执行文件的完全限定路径(可以是可执行脚本)。 That script must return basically immediately so that the jvm can continue and shutdown. 该脚本必须立即返回,以便jvm可以继续并关闭。 So it needs to attempt to stop and start tomcat in the background. 所以它需要尝试在后台停止并启动tomcat。 This may result in effectively 2 scripts: 这可能会导致2个脚本:

Script 1: 脚本1:

#!/bin/bash
script2.sh &

Script 2: 脚本2:

# stop tomcat
# make sure it is dead (kill "zombie" process if necessary)
# start tomcat

The -XX:OnOutOfMemoryError shoudl point to script 1. -XX:OnOutOfMemoryError shoudl指向脚本1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM