从应用程序内请求Java堆转储(核心转储)

从应用程序内请求Java堆转储(核心转储)

问题描述:

我需要一种方法从应用程序中请求堆转储

I need a way to request a heap dump from within the application.

基本原理:遇到特定错误情况时,我'我想转储堆,这样我就能看到内存中的内容。

Rationale: When I encounter a specific error condition, I'd like to dump heap, so that I can see what is holding on to the memory.

但是我想自动化这个(例如,当我检测到时已经发生了一些特定的情况。或者当看门狗不再获得它的ping时。当某些测试失败时)。因此,我需要一种从应用程序本身转储堆的方法。我似乎无法用MX bean找到它。虽然MX Beans可以提供非常好的堆栈跟踪以及监视器和可拥有的同步器信息,死锁和争用信息,但我似乎无法找到请求堆转储的方法。有没有这样的方式?或者通过一些间接方式,例如,这些JVisualVM事情是如何做到的?并且可以告诉JVM在OutOfMemoryExceptions上转储核心。?

But I would like to automate this (For example, when I detect that some specific condition has occurred. Or when a watchdog doesn't gets its pings anymore. When some test fails). Thus I need a way to dump the heap from within the application itself. I can't seem to find it with the MX beans stuff. Although the MX Beans can give very nice stack traces with monitor and "ownable synchronizer" info, deadlock and contention info, I can't seem to find a way to request a heap dump. Are there any such way? Or by some indirect means, for example how does these JVisualVM things do it? And one can tell the JVM to dump core on OutOfMemoryExceptions..?

如果它不足以转储堆 OutOfMemoryError ,有一个依赖于HotSpot的方式如果没有问题,请以编程方式从Java应用程序中转储堆