垃圾收集通知? [英] Garbage collection notification?

查看:88
本文介绍了垃圾收集通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用JVM注册一个回调,所以我知道什么时候垃圾回收正在发生。有没有办法做到这一点?编辑:我想这样做,所以我可以注销垃圾收集时发生在我的应用程序日志,所以我可以看到它是否与我看到的问题相关。打开-Xloggc很有帮助,但将GC日志(使用自应用程序启动后的秒数)的时间集成到我的主应用程序日志中有点棘手。



编辑2012年4月:截至Java7u4,您可以从GarbageCollectorMXBean(一个漂亮的示例 )。

解决方案

从Java7u4开始,您可以从GarbageCollectorMXBean获取通知。请参阅 http://docs.oracle.com /javase/7/docs/jre/api/management/extension/com/sun/management/GarbageCollectionNotificationInfo.html


I'd like to register a callback with the JVM so I know when garbage collection is happening. Is there any way to do this?

EDIT: I want to do this so I can log out when garbage collection happens in my application log, so I can see if it correlates to problems I'm seeing. Turning on -Xloggc is helpful, but it is a little tricky to integrate the times from the GC log (which use seconds since app start) into my main application log.

EDIT April 2012: As of Java7u4, you can get notifications from the GarbageCollectorMXBean (a nice example).

解决方案

As of Java7u4, you can get notifications from the GarbageCollectorMXBean. See http://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/GarbageCollectionNotificationInfo.html

这篇关于垃圾收集通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆