Java 如何从运行 tomcat 7 中获取堆转储

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

ways how to get heap dump from running tomcat 7

javatomcat7heap-dump

提问by emdhie

I've tried this Get a heapdump on JVM from Tomcat 6but it doesn't work for me, Is there other ways to get heap dump from tomcat server? Thanks in advance!

我试过这个Get a heapdump on JVM from Tomcat 6但它对我不起作用,还有其他方法可以从 tomcat 服务器获取堆转储吗?提前致谢!

回答by Taky

The easiest way to get heap dump is to use jmap. On the machine with java process execute jmap command. Example of usage:

获得堆转储的最简单方法是使用jmap。在带有 java 进程的机器上执行 jmap 命令。用法示例:

jmap -dump:file=/mnt/heapdump_2013-04-01.data?29842

use jpsto know java Pid.

使用jps了解 java Pid。



Also you can make heap dump via jvisualvm. You can connect to the remote machine via jmxor jstatd. You can make heapdump and store on the remote machine.

您也可以通过jvisualvm进行堆转储。您可以通过jmxjstatd连接到远程机器。您可以在远程机器上进行堆转储和存储。

To analyze heapdumps can advice you: MAT. Very powerful tool which allow you to quickly understand problems. You can find heregood inro to the MAT.

要分析 heapdumps 可以建议您:MAT。非常强大的工具,可让您快速了解问题。你可以在这里找到很好的 MAT 介绍。



If you don't want to stop application for a long time you can make binary dump(You can use gcore or gdb). And you can use jmap to analyze gdb dump. More information you can read on the atlassian blog. Beware of someissues.

如果您不想长时间停止应用程序,您可以进行二进制转储(您可以使用 gcore 或 gdb)。您可以使用 jmap 来分析 gdb dump。您可以在Atlassian 博客上阅读更多信息。当心一些问题

回答by piet.t

Another way besides the "Dump heap"-Button of jvisualvm is via the JMX-interface. This way even allows you to specify where to store the dump.

除了 jvisualvm 的“转储堆”按钮之外,另一种方法是通过 JMX 接口。这种方式甚至允许您指定存储转储的位置。

connect to tomcat's JMX-server using jconsole or jvisualvm with JMX-plugin. Then got to com.sun.management-> HotSpotDiagnotic-> Operations. Next to dumpHeapfill in the two parameters. From oracle's documentation (see here):

使用带有 JMX 插件的 jconsole 或 jvisualvm 连接到 tomcat 的 JMX 服务器。然后到com.sun.management-> HotSpotDiagnotic-> Operations。接下来dumpHeap填写两个参数。来自 oracle 的文档(参见此处):

Parameters:

outputFile - the system-dependent filename

live - if true dump only live objects i.e. objects that are reachable from others

参数:

outputFile - 系统相关文件名

live - 如果真的只转储活动对象,即可以从其他人访问的对象

Then press dumpHeapand watch the VM freeze for some time while writing the dump.

然后dumpHeap在写入转储时按下并观察 VM 冻结一段时间。

回答by Alireza Fattahi

I recommend visual VM http://visualvm.java.net/It is a all in one tool which can connect to tomcat, create and read heap dump, creates thread dump, cpu and memory sampler.

我推荐visual VM http://visualvm.java.net/它是一个多合一的工具,可以连接到tomcat,创建和读取堆转储,创建线程转储,cpu和内存采样器。

If you use new jdk 1.7, VisualVM is already packaged in your jdk folder.

如果您使用新的 jdk 1.7,VisualVM 已经打包在您的 jdk 文件夹中。