我有JVM选项-XX:PrintGCApplicationStoppedTime打印真正的“GC停止世界时间” .
例:
应用程序线程停止的总时间:0.0018219秒
应用程序线程停止的总时间:0.0016542秒
应用程序线程停止的总时间:0.0015797秒
我需要通过java代码计算“GC停止世界” . 我该怎么做 ?
请注意 PrintGCApplicationStoppedTime 打印 safepoint time 而不是 GC time .有关详细信息,请参阅this answer .
PrintGCApplicationStoppedTime
您可以通过JDK特定(即不受支持的)MXBean获取安全点的累积时间 . 此值等于 Total time for which application threads were stopped 消息中打印的所有数字的总和 .
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());
1 回答
请注意
PrintGCApplicationStoppedTime
打印 safepoint time 而不是 GC time .有关详细信息,请参阅this answer .
您可以通过JDK特定(即不受支持的)MXBean获取安全点的累积时间 . 此值等于
Total time for which application threads were stopped
消息中打印的所有数字的总和 .