CrazyCoder
CrazyCoder

Reputation: 2605

What does GarbageCollectorMXBean::getCollectionCount means?

The javadoc says returns the total number of collections that have occurred, is it since the start of the JVM?

I am using G1GC, and I see values are going up & down for e.g. at T1 - 250 and T2 - 91 and T3 - 150 so I doubt it is from the start of the time.

So could someone please let me know what does getCollectionCount returns? Does it differ for each garbage collector?

I have gone through couple of answers here already but none seems to answer the above question.

Thanks in advance

Upvotes: 1

Views: 920

Answers (1)

apangin
apangin

Reputation: 98350

GarbageCollectorMXBean.getCollectionCount() returns the total number of collections since JVM start. The counter never goes down. If you see it decreasing, there is probably something wrong in a way how you get it, or it means the JVM has restarted between samples.

Note that there can be multiple GarbageCollectorMXBeans in a single JVM. In particular, G1 GC registers two MXBeans:

  • java.lang:name=G1 Old Generation,type=GarbageCollector
  • java.lang:name=G1 Young Generation,type=GarbageCollector

Each bean has its own counter that increments independently. Make sure you query the same bean when comparing values.

Upvotes: 1

Related Questions