java Tomcat 在没有任何日志或任何堆栈的情况下停止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10300883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:27:31  来源:igfitidea点击:

Tomcat stopped without any log or any stack

javatomcatcrashvirtual-machine

提问by Remi

We have trouble with Tomcat 5.5 which stops at night on our production servers (Linux CentOS 4.8) and we have no idea why it stops... There is no Tomcat's log in catalina.out or any application's log.

我们在使用 Tomcat 5.5 时遇到了问题,它在我们的生产服务器 (Linux CentOS 4.8) 上晚上停止,我们不知道它为什么会停止...... catalina.out 中没有 Tomcat 的日志或任何应用程序的日志。

We tried different things to find why the server stops:

我们尝试了不同的方法来找出服务器停止的原因:

  • configure Tomcat to be able to generate a core dump
  • instrument System.exit()method with javassist to find if the method was called
  • add a shutdown hook to the JVM (with Runtime.getRuntime().addShutdownHook())
  • 配置 Tomcat 以生成核心转储
  • System.exit()使用 javassist检测方法是否被调用
  • 向 JVM 添加关闭钩子(使用Runtime.getRuntime().addShutdownHook()

None of them worked, we have no core dump, the Exit method and the shutdown hook are not called. My conclusions are:

他们都没有工作,我们没有核心转储,没有调用 Exit 方法和关闭钩子。我的结论是:

  • The VM is not terminated properly but crash without any log.
  • 虚拟机没有正确终止,而是在没有任何日志的情况下崩溃。

Any idea or log to read to find why Tomcat stops?

任何想法或日志阅读以找出Tomcat停止的原因?

回答by MK.

1) Make sure you know where stderr is redirected and check if anything got printed there.

1) 确保您知道 stderr 被重定向到哪里,并检查那里是否打印了任何内容。

2) Check the memory limits on Tomcat and how much free memory does the system have. Review the Linux system logs under /var/log to see if anything suspicious happened during the time. For example, kernel can randomly kill a process (almost) without a trace if the system is running low on memory.

2)查看Tomcat的内存限制以及系统有多少空闲内存。查看 /var/log 下的 Linux 系统日志,看看在此期间是否发生了任何可疑的事情。例如,如果系统内存不足,内核可以随机杀死一个进程(几乎)而不留痕迹。

We've ran 5.5 in production for years and never had any unexplained shutdowns, FWIW.

FWIW,我们已经在生产环境中运行 5.5 多年,从未发生过任何无法解释的停机。

回答by Kaushal Dokania

This worked for me.

这对我有用。

As suggested here in other answers checked system logs in /var/log/messagesbut permission denied for me. So, I used dmesgcommand instead and got this in the logs

正如其他答案中所建议的那样,已检查系统登录,/var/log/messages但我的权限被拒绝。所以,我改用dmesg命令并将其记录在日志中

"Out of memory: Kill process 14606 (java) score 106 or sacrifice child".

“内存不足:杀死进程 14606 (java) 得分 106 或牺牲孩子”。

In the output I also noticed Swap Memory free 0 K. Ran topcommand to confirm the same. So, somehow there was a high memory usage which caused the OS to kill my tomcat process.

在输出中,我还注意到Swap Memory free 0 K。Rantop命令确认相同。因此,不知何故,内存使用率很高,导致操作系统终止了我的 tomcat 进程。

After spending hours finally got the reason.

花了几个小时终于得到了原因。

ps -ef | grep tomcatshowed that there were several tomcat processes running for the same application. It seems that, earlier tomcat shutdowns might not have been completed successfully and due to some reason the processes were not killed even after the shutdown, which was causing the high memory usage.

ps -ef | grep tomcat显示有多个 tomcat 进程在为同一个应用程序运行。看来,早期的 tomcat 关闭可能没有成功完成,并且由于某种原因,即使关闭后进程也没有被杀死,这导致了高内存使用率。

So, killed all running tomcat processes using kill. SWAP memory got freed.

因此,使用kill. SWAP 内存被释放。

Started tomcat again, worked fine. :)

再次启动tomcat,工作正常。:)

回答by Eugene Retunsky

Most probably there is a stack-overflow exception. This is typical behavior of Tomcat when it happens. For example, you're trying to serialize to JSON or XML beans with cyclic dependencies (but without handling of the cycles).

很可能存在堆栈溢出异常。这是 Tomcat 发生时的典型行为。例如,您尝试序列化为具有循环依赖项的 JSON 或 XML bean(但不处理循环)。

Everytime I had this issue (several times) it always has been this one. All other stops are usually logged properly (like OutOfMemory etc).

每次我遇到这个问题(几次)时,总是这个问题。所有其他停止通常都被正确记录(如 OutOfMemory 等)。

This type of stops leaves no trace anywhere.

这种类型的停止在任何地方都不会留下任何痕迹。

回答by Eugene Retunsky

Tomcat 7 has an option inside catalina to prevent the System.exit class call or something similar: http://ci.apache.org/projects/tomcat/tomcat7/docs/security-manager-howto.html.

Tomcat 7 在 catalina 中有一个选项来防止 System.exit 类调用或类似的东西:http: //ci.apache.org/projects/tomcat/tomcat7/docs/security-manager-howto.html

Maybe there's a similar option for the 5.5 version. Try the documentation.

也许 5.5 版本有类似的选项。尝试文档。

There are options to redirect the output to the same console that you use to start Tomcat. This information is redirected to logs when you execute on Unix based systems, on Windows, it remains with the console if not redirected.

有一些选项可以将输出重定向到用于启动 Tomcat 的同一控制台。当您在基于 Unix 的系统上执行时,此信息将重定向到日志,在 Windows 上,如果未重定向,它会保留在控制台中。