我有JVM选项-XX:+ PrintGCApplicationStoppedTime打印真实" GC停止世界时间"。
示例:
我需要计算" GC停止世界"通过java代码。我该怎么办?
答案 0 :(得分:4)
请注意PrintGCApplicationStoppedTime
打印安全点时间而不是 GC时间。
有关详细信息,请参阅this answer。
您可以通过JDK特定(即不受支持的)MXBean获取安全点的累积时间。此值等于Total time for which application threads were stopped
消息中打印的所有数字的总和。
sun.management.HotspotRuntimeMBean runtime =
sun.management.ManagementFactoryHelper.getHotspotRuntimeMBean();
System.out.println("Safepoint time: " + runtime.getTotalSafepointTime() + " ms");
System.out.println("Safepoint count: " + runtime.getSafepointCount());