如何在不先进行垃圾收集的情况下在 Java 5 上进行堆转储?

2022-01-16 00:00:00 garbage-collection java heap-memory

我们有一个运行 Java 5 的长期运行的服务器应用程序,对其进行分析我们可以看到老一代随着时间的推移缓慢增长.它在完整的 GC 上被正确释放,但我希望能够使用堆转储查看 Eclipse MAT 中无法访问的对象.我已经使用 +XX:HeapDumpOnCtrlBreak 成功获得了堆转储,但是 JVM 总是在转储堆之前进行 GC.显然这不会发生在 Java 6 上,但我们现在停留在 5 上.有什么办法可以预防吗?

We have a long running server application running Java 5, and profiling it we can see the old generation growing slowly over time. It's correctly freed on a full GC, but I'd like to be able to look at the unreachable objects in Eclipse MAT using a heap dump. I've successfully obtained a heap dump using +XX:HeapDumpOnCtrlBreak, but the JVM always does a GC before dumping the heap. Apparently this doesn't happen on Java 6 but we're stuck on 5 for now. Is there any way to prevent this?

推荐答案

我建议使用 3rd-party profiler,例如 YourKit,它可以让您在不先启动 GC 的情况下拍摄快照.额外的好处是,您可以在没有整个 ctrl-break 恶作剧的情况下拍摄快照.

I suggest a 3rd-party profiler such as YourKit, which may allow you to take snapshots without kicking off the GC first. Added bonus, you can take a snapshot without the whole ctrl-break shenanigans.

相关文章