How does the JMX (Java Management Extensions) getCollectionTime method calculate GC time?

in JAVA, running programs can be managed and monitored through the JMX interface.

you can obtain the program GC through the open function of JMX, as follows:

public class TestJMX {
    public static void main(String[] args) {
        List<GarbageCollectorMXBean> garbageCollectorMXBeanList = ManagementFactory.getGarbageCollectorMXBeans();
        for (final GarbageCollectorMXBean garbageCollector : garbageCollectorMXBeanList) {
            System.out.println("name:" + garbageCollector.getName());
            System.out.println("CollectionCount:" + garbageCollector.getCollectionCount());
            System.out.println("CollectionTime" + garbageCollector.getCollectionTime());
        }
    }
}

first get all the GC scenes through the ManagementFactory.getGarbageCollectorMXBeans () method.

what is more important is that the time spent on this GC can be obtained through the getCollectionTime method.

for the entire Young GC, process, STW, can assume that the time returned by the method is the time of the entire YGC.

for the old age, CMS GC, is generally used in the CMS process, there are a large number of concurrent processes, and the real STW stage is only the initial mark and remark stages.

excuse me, is the time returned by the CMS GC,getCollectionTime method the sum of the initial mark and remark phases?

Feb.28,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7ab7eb-1dec1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7ab7eb-1dec1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?