从应用程序内请求 java 堆转储(核心转储)
我需要一种从应用程序内部请求堆转储的方法。
理由:当我遇到特定的错误情况时,我想转储堆,以便我可以看到内存中占用了什么。
但我想自动执行此操作(例如,当我检测到发生了某些特定情况时。或者当看门狗不再获得其 ping 时。当某些测试失败时)。因此,我需要一种从应用程序本身内部转储堆的方法。我似乎找不到 MX beans 的东西。尽管 MX Bean 可以提供非常好的堆栈跟踪,包括监视器和“可拥有的同步器”信息、死锁和争用信息,但我似乎找不到请求堆转储的方法。有这样的办法吗?或者通过一些间接的方式,例如这些JVisualVM的东西是如何做到的?并且可以告诉 JVM 在 OutOfMemoryExceptions 上转储核心..?
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.
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..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果还不够使用
-XX:HeapDumpOnOutOfMemoryError
命令行参数用于在OutOfMemoryError
上转储堆,有一种特定于 HotSpot 的方式 以编程方式转储堆来自 Java 应用程序:If it's not enough to use the
-XX:HeapDumpOnOutOfMemoryError
command line argument to dump heap onOutOfMemoryError
, there's a HotSpot-specific way of programmatically dumping heap from Java applications:如何使用 VM 选项 -XX:+HeapDumpOnOutOfMemoryError 告诉 HotSpot VM 在内存不足时生成堆转储?
What about using the VM option
-XX:+HeapDumpOnOutOfMemoryError
to tell the HotSpot VM to generate a heap dump when it runs out of memory?