JVM GC Event Software Notification

I would like to know how much time was spent on the GC and how much memory was collected, but not on the analysis of the GC logs (i.e. the analysis of what I got from -XX: + PrintGCWhatever).

I found that I can use Sun ManagementFactory to get the GarbageCollectorMXBean, which can give me some GCInfo object containing memory information, but I have no guarantee that I can collect all the GC through this value.

Does anyone know a way to do this in code?

+7
java garbage-collection jvm
source share
2 answers

GarbageCollectorMXBean is the best I could find on the Sun JVM. In my experience, it really comes close to what you are asking for.

I assume you might have a special thread that woke up from time to time to get GC statistics. This will add some determinism when statistics are collected.

+4
source share

Given the range of tools for getting this information, you better use them to analyze your GC's behavior and optimize for it. for example using a memory profiler.

The problem is that the information is not very useful if it does not indicate a solution to the problem. (What you can fix)

0
source share

All Articles