0

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

CrazyCoder
  • 2,465
  • 8
  • 36
  • 57
  • Are you sure you don't have the exact same situation as the person in the question you linked? With the wrapper? – Kayaman Jun 09 '22 at 14:04
  • @Kayaman, Are you saying it returns the number of GCs from the last poll on getCollectionCount? If yes, can you please let me know the source/document? – CrazyCoder Jun 09 '22 at 14:08
  • Well all I based my comment on was the link's "What I was looking at was a wrapper over GarbageCollectorMXBean...". Are you sure you're not looking at a wrapper? – Kayaman Jun 09 '22 at 15:35
  • To write a wrapper, one should know how to interpret the values returned by the getCollectionCount function, i.e., Is it since the start of JVM or the last poll?. Only then can we be able to design and write the wrapper. – CrazyCoder Jun 10 '22 at 04:12
  • I wasn't asking you to design a wrapper, I was asking if you were using one. I guess the answer is "I don't know if I'm using a wrapper". – Kayaman Jun 10 '22 at 10:43

1 Answers1

0

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.

apangin
  • 92,924
  • 10
  • 193
  • 247