gpt4 book ai didi

Java 垃圾收集 GcInfo.getDuration() 将单位从毫秒更改为微秒

转载 作者:行者123 更新时间:2023-12-01 13:17:36 25 4
gpt4 key购买 nike

我目前正在处理 com.sun.management.GcInfo 类的一些烦恼。我通过添加 GC 通知监听器改进了我们的服务器日志。每当发生主要 GC 时,我都会记录它所花费的持续时间(以及其他一些内容)。“官方”方法是为 GarbageCollectorMXBean bean 添加通知监听器。一切都按预期进行。我了解 GC 的情况,对于每个 GarbageCollector 我都会得到一个com.sun.management.GcInfo 具有持续时间的对象。我的烦恼是当前文档 7u51 声明持续时间的值以毫秒为单位。我也在 7u11 下运行我们的服务器应用程序,持续时间似乎长了 1000 => 微秒。有人有这方面的信息吗?他们在哪个 Java 版本中改变了这一点?

最佳答案

这是一个bug在 JVM 中。 GcInfo 方法返回刻度而不是毫秒。

错误描述是这样说的:

When grabbing GarbageCollectorMXBean from the ManagementFactory, it is NOW possible (in Java 7) to cast the underlying bean implementation into a NotificationBroadcaster and add a NotificationListener. Doing this causes the JVM to report on GC events after they're done. In the JVM, GCNotifier::pushNotification puts the "raw" GCStatInfo data (containing start/end ticks) onto the request queue. GCNotifier::sendNotification constructs GcInfo from this data WITHOUT converting the ticks to millis. When the listener gets access to the GcInfo object, a call to getDuration() returns elapsed ticks vs. elapsed millis (contrary to comments in the source code).

因此,您应该使用 JVM 版本 7u51 或更高版本来获取正确的 GC 信息。

关于Java 垃圾收集 GcInfo.getDuration() 将单位从毫秒更改为微秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22344264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com