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?