Java Tomcat 自动关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1003738/
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-08-11 22:08:05  来源:igfitidea点击:

Tomcat shuts down automatically

javaapachetomcat

提问by

I'm using Apache and Tomcat on a Windows server and since this morning, Tomcat stops working without any logs. It doesn't hang, it just shut down.
There's no log in Tomcat, the CPU/Memory are fines, there are no System.Exitin my code.

我在 Windows 服务器上使用 Apache 和 Tomcat,从今天早上开始,Tomcat 在没有任何日志的情况下停止工作。它没有挂起,它只是关闭。
Tomcat 没有登录,CPU/内存很好,System.Exit我的代码中没有。

Anybody ever had this problem?

有人遇到过这个问题吗?

It happens at random, after 5-10 minutes. The application responds normally and sometime, boom.. stops working.

它在 5-10 分钟后随机发生。应用程序正常响应,有时,boom.. 停止工作。

UPDATE : Still no clue. The Admin team will install the webapp on another box...

更新:仍然没有线索。管理团队将在另一个盒子上安装 webapp...

回答by neesh

things to look for in debugging an issue like this:

在调试这样的问题时要寻找的东西:

  • Look at the logs directory ($TOMCAT_ROOT/logs) to make sure none of the log files have any stack traces
  • Look at the tomcat startup script to make check the location of the log files to see if the logs are not being written to another directory.
  • Another reason could be some other user/process could be issuing a kill -9 that could kill tomcat without giving it any chance to log errors.
  • 查看日志目录 ($TOMCAT_ROOT/logs) 以确保所有日志文件都没有任何堆栈跟踪
  • 查看 tomcat 启动脚本以检查日志文件的位置,以查看日志是否未写入其他目录。
  • 另一个原因可能是其他一些用户/进程可能发出 kill -9 可以杀死 tomcat 而不给它任何机会记录错误。

回答by Matt Solnit

This sounds like the JVM is crashing. Have you looked for a JVM crash log? It typically has a name like hs_err_pid*.log and is created in the JVM's working directory.

这听起来像是 JVM 崩溃了。您是否查找过 JVM 崩溃日志?它通常具有类似 hs_err_pid*.log 的名称,并在 JVM 的工作目录中创建。

If you find a file like this and upload it, then we can probably help more.

如果您找到这样的文件并将其上传,那么我们可能会提供更多帮助。

Some questions:

一些问题:

  • Have you recently changed the version of Java you are using?
  • What is the exact version of Tomcat you are using?
  • Are you using Tomcat Native (the Apache Portable Runtime)?
  • 您最近是否更改了您使用的 Java 版本?
  • 您使用的 Tomcat 的确切版本是什么?
  • 您在使用 Tomcat Native(Apache Portable Runtime)吗?

回答by akf

another possibility is that some process was started this morning on the box that is binding to a port that your server requires.

另一种可能性是今天早上在绑定到服务器所需端口的盒子上启动了某个进程。

回答by Macke

Are your servlets or one of it's dependencies allowed to call System.exit()? (Not sure how locked down Tomcat VMs are in that sense)

是否允许您的 servlet 或其依赖项之一调用 System.exit()?(不确定在这个意义上如何锁定 Tomcat VM)

I've had developers thinking it's ok to use exit(666); on detecting a non-invertable matrix (which isn't good, but sure as heck not fatal). Arrgh. Perhaps you have some similar culprit in your system?

我让开发人员认为可以使用 exit(666); 关于检测不可逆矩阵(这不好,但肯定不是致命的)。啊。也许您的系统中有一些类似的罪魁祸首?

回答by Phanindra

Recently I had this problem, If somebody faces the same issue in future I hope this will help.

最近我遇到了这个问题,如果将来有人遇到同样的问题,我希望这会有所帮助。

Scenario:Tomcat shuts down without any logs or errors

场景:Tomcat 在没有任何日志或错误的情况下关闭

Root Cause for my problem:synchronized method accessed from a task using TimerTask

我的问题的根本原因:使用从任务访问的同步方法TimerTask

I had a singleton class with a synchronized method accessed from various threads based on timer or user action some times this method will take up to few minutes to complete. When TimerTaskis waiting on this method for sometime (I guess timer is timed out /thread is killed or something is happening in the background) and the moment the lock on the method is released the tomcat is getting killed.

我有一个单例类,其中包含基于计时器或用户操作从各种线程访问的同步方法,有时此方法需要几分钟才能完成。当TimerTask等待这个方法一段时间(我猜计时器超时/线程被杀死或后台发生了什么)并且方法上的锁被释放的那一刻,tomcat被杀死了。

So I removed synchronized keyword and removed singleton and made some code changes for thread safety. Then the problem is gone.

所以我删除了 synchronized 关键字并删除了单例,并为线程安全做了一些代码更改。那么问题就没有了。

How I found out:I had a log statement in the first line of synchronized method and everytime the tomcat shutdowns i found this message in the last few lines.

我是如何发现的:我在同步方法的第一行中有一个日志语句,每次 tomcat 关闭时,我都会在最后几行中发现此消息。

Regards, Phanindra Kasturi

问候, 法宁德拉·卡斯图里

回答by connect2krish

I noticed CATALINA_OPTS in my path and that was set for a lower JVM size. Hence, the crash and no log trace of tomcat was found. The server automatically shutdown in less than 2 hrs.

我注意到我的路径中有 CATALINA_OPTS 并且它被设置为较低的 JVM 大小。因此,找不到tomcat的崩溃和日志跟踪。服务器在不到 2 小时内自动关闭。

check, CATALINA_OPTS or JAVA_OPTS -- these might have jvm settings. either increase them or comment them out and increase the swap memory.

检查,CATALINA_OPTS 或 JAVA_OPTS——这些可能有 jvm 设置。要么增加它们,要么将它们注释掉并增加交换内存。

回答by vierab

I had this problem, and I found the cause at this link. My script to start tomcat had last line tail -f catalina.out. Sometime I did not kill this script, the shell then timed out and killed the script with all child processes, including tomcat.

我遇到了这个问题,我在这个链接中找到了原因。我的启动 tomcat 的脚本有最后一行tail -f catalina.out。有时我没有杀死这个脚本,shell 然后超时并杀死了所有子进程的脚本,包括 tomcat。

回答by Niresh S

“The Service on local computer started and then stopped ,Some services stop automatically if there are not in use by other services or programs.”

“本地计算机上的服务启动然后停止,如果没有其他服务或程序使用,某些服务会自动停止。”

I gone through the problem i have tried so many ways to get out of the problem finally i got the solution as follows.

我经历了这个问题,我尝试了很多方法来摆脱这个问题,最后我得到了如下解决方案。

1)Click RunCommand from start button.

1)从开始按钮 单击运行命令。

2)Enter Services.mscthen click OK,you will get all the services in your computer.

2)输入Services.msc,然后点击确定,您将获得计算机中的所有服务。

3)Select your service and right click on the service and select Properties

3)选择您的服务并右键单击该服务并选择属性

4)Goto Logon Properties and select Local System Accountthen click OK.

4)转到登录属性并选择 本地系统帐户,然后单击确定。

This will work.

这将起作用。

回答by Harpreet Saini

Sometime it happens if some other program is running on the same port. For example Skype. Shut down that program before you start Tomcat.

有时,如果某个其他程序正在同一端口上运行,则会发生这种情况。例如Skype。在启动 Tomcat 之前关闭该程序。

回答by Kaushal Dokania

Faced this issue recently.

最近遇到这个问题。

Scenario: Tomcat started successfully but automatically gets shut down after 1 hour and sometimes this happened after 1 day and nothing is there in tomcat logs.

场景:Tomcat 成功启动,但 1 小时后自动关闭,有时这会在 1 天后发生,并且 tomcat 日志中没有任何内容。

Issue: Actual issue was high memory usage and no free SWAP memory.

问题:实际问题是内存使用率高且没有可用的 SWAP 内存。

How I found the solution

我是如何找到解决方案的

If tomcat don't show any logs, then there must be something in system logs so, I checked /var/log/messagesbut since permission denied for me I tried /var/log/dmesgand got this

如果 tomcat 没有显示任何日志,那么系统日志中肯定有一些东西,所以我检查过,/var/log/messages但由于我的权限被拒绝,我尝试/var/log/dmesg并得到了这个

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

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

In the output I 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 taken successfully and the processes were not killed even after the shutdown due to some reason, 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,工作正常。:)