Programmatic notification of JVM's GC events

I would like to track how much time is spent in GC and how much memory has been collected, but not by analysing GC logs (ie. analyzing what I got from -XX:+PrintGCWhatever).

I found that I can use Sun's ManagementFactory to get a GarbageCollectorMXBean that can give me some GCInfo object containing memory information but I have no guarantee I can collect all GC through this mean.

Does anybody know of a way to do this in code?


GarbageCollectorMXBean is the best I've been able to find on the Sun JVM. In my experience, it actually comes pretty close to what you're asking for.

I imagine you could have a dedicated thread that would wake up from time to time to get the GC stats. This would add some determinism to when the stats are collected.


Given the range of tools to obtain this information, you are better off using those to analysis your GC behaviour and to optimise for it. eg using a memory profiler.

The problem you have is that the information isn't very useful unless it points to a solution to a problem. (Which you can then fix)

链接地址: http://www.djcxy.com/p/49070.html

上一篇: 在java中记录流媒体音频?

下一篇: 编程式通知JVM的GC事件