我可以让 Tomcat 作为转储堆服务运行吗?

发布于 2024-08-19 18:20:38 字数 769 浏览 7 评论 0原文

我正在尝试让 Tomcat(当前在 Windows 2003 机器上作为服务运行)在发生 OutOfMemoryError 时转储堆。

(Tomcat 正在运行 Hudson,它在构建的尾部报告了堆空间问题。手动运行构建不会产生此类错误。Hudson 人员需要堆转储才能开始。)

按照其他地方的指示,我已经告诉过通过将以下内容添加到 JVM 选项,Apache 服务监视器来配置用于运行 Tomcat 的 JVM,以便在遇到 OutOfMemoryError 时转储堆: -XX:+HeapDumpOnOutOfMemoryError 然后我再次运行构建。果然,它报告存在堆错误。我扫描整个磁盘,查找默认的 java_pid123.hprof 文件(其中显然 123 被 JVM 的 PID 替换)。任何地方都不存在 .hprof 文件。

我陷入了第 22 条陷阱:我需要 Hudson 人员的堆转储来修复他们的内存泄漏,但如果我在 Tomcat 下运行 Hudson,我无法获得堆转储。

当 Tomcat 作为 Windows 服务运行时,是否有某种特殊的方法可以在发生 OutOfMemoryError 时从中获取堆转储?

我尝试过的另一件事是告诉它在“启动”和“关闭”选项卡上使用“Java”选项而不是“jvm”选项。我相信这应该告诉服务管理器尝试使用 Java 可执行命令启动 Tomcat,而不是直接启动 jvm.dll。当我这样做时,服务将不会启动。

当然其他人也遇到过类似的问题吗?

I am attempting to have Tomcat, which is currently running as a service on a Windows 2003 box, dump heap on an OutOfMemoryError.

(Tomcat is running Hudson, which is reporting a heap space problem at the tail end of my build. Running the build manually produces no such error. The Hudson guys need a heap dump to get started.)

As instructed elsewhere, I've told the Apache Service Monitor to configure the JVM it uses to run Tomcat to dump heap when an OutOfMemoryError is encountered by adding the following to the JVM options:
-XX:+HeapDumpOnOutOfMemoryError
Then I run the build again. Sure enough, it reports there was a heap error. I scan the entire disk looking for the default java_pid123.hprof file (where obviously 123 is replaced by the PID of the JVM). No .hprof files exist anywhere.

I am caught in a catch 22: I need the heap dump for the Hudson guys to fix their memory leak, but I can't get the heap dump if I run Hudson under Tomcat.

Is there some special way, when Tomcat is running as a Windows service, to get a heap dump from it on an OutOfMemoryError?

The other thing I've tried is to tell it, on the Startup and Shutdown tabs, to use the "Java" option instead of the "jvm" option. I believe this should tell the Service Manager to attempt to start Tomcat with a Java executable command instead of launching the jvm.dll directly. When I do this, the service won't start.

Surely someone else has had a similar problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

弥枳 2024-08-26 18:20:38

终于把这个问题放在床上后,我想为其他可能有同样问题的人回答这个问题。

首先,如果您在 Windows 上安装 Tomcat,请不要使用 .exe 安装程序,即使它是由 Apache 推广的。无论您做什么,它都不允许您以系统帐户以外的任何身份运行 Tomcat。系统帐户似乎没有在当前目录中写入 .hprof 文件的权限,并且无论进行多少 Windows 安全调整似乎都无法解决此问题。

好的,您已经从 .zip 发行版安装了 Tomcat。使用 service.bat 脚本将其安装为服务。确保将其设置为以您专门为此目的创建的特定用户身份运行。还要确保您希望 Tomcat 在发生堆转储时写入的文件夹可由该用户写入。

编辑 service.bat 文件以在正确的位置包含 -XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=C:\whatever 选项地方(可以放置 JVM 选项的地方)。那应该可以解决问题。

After finally putting this one to bed, I wanted to answer this for others who might have the same problem.

First, if you install Tomcat on Windows, do not use the .exe installer, even though it is promoted by Apache. It will not let you run Tomcat as anything other than the system account, no matter what you do. It appears that the system account does not have privileges to write .hprof files in the current directory, and no amount of Windows security tweaking appears to make this problem go away.

OK, so you've installed Tomcat from the .zip distribution. Install it as a service using the service.bat script. Make sure it is set to run as a specific user that you created specifically for this purpose. Make sure as well that the folder you want Tomcat to write to in the event of a heap dump is writable by that user.

Edit the service.bat file to include the -XX:+HeapDumpOnOutOfMemoryError and the -XX:HeapDumpPath=C:\whatever options in the correct place (where you can put JVM options). That should do the trick.

四叶草在未来唯美盛开 2024-08-26 18:20:38

我找到了以下链接,它描述了如何配置tomcat服务(包括设置java参数)。不确定它是否适用于您正在运行的版本。

http://tomcat.apache.org/tomcat-5.5- doc/windows-service-howto.html

I found the following link, which describes how to configure the tomcat service (includes setting the java parameters). Not sure if it applies to the version you are running.

http://tomcat.apache.org/tomcat-5.5-doc/windows-service-howto.html

我不在是我 2024-08-26 18:20:38

当java进程作为窗口服务运行时,您可以使用以下步骤生成堆转储,

  1. 以管理员版本的JDK(用于jmap命令)和JRE(Java应用程序运行环境)运行命令控制台
  2. 应该相同。
  3. 从任务管理器获取该java应用程序正在运行的窗口进程的PID号
  4. 执行以下命令

jmap -dump:file=d:\heapdump\myHeapDump.hprof -F #PID_No#

如果 JDK/JRE 7 出现任何异常,请尝试使用 JDK/JRE 8 进行相同操作
实际上,我在使用 JDK 7 的 jmap 中遇到了一些问题,但是当我迁移到 JDK 8 时,我能够使用相同的命令成功生成堆转储

When java process running as window service you can generate the heapdump using below steps,

  1. Run the command console as Administrator
  2. version of JDK (for jmap command) and JRE (Java app run environment) should be same.
  3. Get the PID no of running window process for that java application from task manager
  4. Execute below command

jmap -dump:file=d:\heapdump\myHeapDump.hprof -F #PID_No#

If got any exception with JDK/JRE 7 try the same with JDK/JRE 8
Actually I faced some issue in jmap with JDK 7, but when i moved to JDK 8, I were able to successfully generate the heap dump using same command

携君以终年 2024-08-26 18:20:38

.hprof 文件转储到当前目录中。这对于 Windows 服务到底意味着什么,谁也说不准,假设它意味着什么。

我建议发布一个新问题(在 http://superuser.com 上),询问“当前目录”对于 Windows 服务意味着什么。

The .hprof files are dumped in the current directory. Exactly what that means for a windows service is anyone's guess, assuming it means anything.

I suggest posting a new question (on http://superuser.com) asking what "current directory" means for a windows service.

哥,最终变帅啦 2024-08-26 18:20:38

来自 20 个使用 Tomcat 的技巧生产

将以下内容添加到 catalina.sh(或 Windows 的 catalina.bat)中的 JAVA_OPTS 中: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/j2ee/heapdumps

From 20 Tips for Using Tomcat in Production

Add the following to your JAVA_OPTS in catalina.sh (or catalina.bat for Windows): -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/j2ee/heapdumps

傲娇萝莉攻 2024-08-26 18:20:38

如果您使用 .exe 安装了 tomcat,则可以将 tomcat 服务配置为使用本地系统帐户以外的帐户,并且可以在创建转储文件的目录“c:\whatever”上分配该用户权限。这里要记住的一件事是 tomcat 服务不能使用具有管理权限的帐户运行。因此,在windows中创建一个简单的用户(用户组的成员)并将tomcat服务设置为使用该帐户。并授予该用户对“c:\whatever”目录的权限。这解决了用户目录权限问题,但您必须针对内存转储错误配置 tomcat。

if you have installed tomcat with .exe you can configure tomcat service to use account other than local system account and you can assign that user rights on directory "c:\whatever" where you are creating your dump file. one thing here to remember tomcat service don't run with account having administrative privileges. so create a simple user in windows(member of user group) and set tomcat services to user this account. and give that user rights on "c:\whatever" directory. This resolves the user directory rights issue but you have to configure tomcat for Memory dumps errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文