在未捕获的异常上生成Java堆转储 [英] Generate Java Heap Dump on uncaught Exception
问题描述
我尝试在触发未捕获的异常时生成堆转储。我尝试使用jmap,但因为当异常发生时进程已完成,这是不可能的。
I try to generate a Heap Dump when a uncaught exception is fired. I tried using jmap, but because the process is finished when the exception happens this is not possible.
使用UncaughtExceptionHandler也不是选项,因为我只有执行程序的二进制文件。
Using a UncaughtExceptionHandler is no option either, because I only have the binaries of the programs that is executed.
任何人都可以帮助我吗?
Can anyone help me?
编辑:重要的是该技术可通过命令行或类似,因为我需要自动化这个。使用GUI是没有选择
It is important that the technique is available through a command line or similar, because I need to automated this. Using a GUI is no option
推荐答案
尝试将处理放入deamon线程。这样您就可以使用内存分析工具访问它。 JVisualVM是一个JDK工具,您可以在JAVA_HOME \ bin中找到它。
Try to put your processing into a deamon thread. this way you can access it with memory analysis tools. JVisualVM is a JDK tool you can find it in your JAVA_HOME\bin.
还有另一种方法,称为转储分析器。使用以下JVM参数运行应用程序:
There are also another way, called dump analyser. You run your application with these JVM parameters :
-
-XX:+ HeapDumpOnOutOfMemoryError
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath =your_path
-XX:HeapDumpPath="your_path"
但只有在你有OutOfMemoryError。尝试找出是否可以为任何性能生成转储。
But this is used only if you have an OutOfMemoryError. Try to find if it's possible to generate the dump for any performance.
另一个基于eclipse的好工具是 MemoryAnalyzer
Another good eclipse based tool is MemoryAnalyzer
这篇关于在未捕获的异常上生成Java堆转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!