如何打印java类垃圾回收事件? [英] Howto print java class garbage collection events?

查看:181
本文介绍了如何打印java类垃圾回收事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Java版本1.5.0_14
Java(TM)2运行时环境标准版(build 1.5.0_14-b03)
Java HotSpot(TM)服务器虚拟机(build 1.5.0_14-b03,混合模式)

我试图调试一个NullPointerException我得到传递一个引用静态定义的字段。更具体地说,我在Drools3工作记忆实例上设置全局。

  workingMemory.setGlobal(log workingMemorieslog); 

我的假设是静态定义字段的类是垃圾回收。 (接收类必须使用WeakReference或类似的东西,我不知道)



你建议如何调试?
我认为,如果我可以确切地知道JVM的GC卸载一个类的类/实例,那么我可以缩小错误行为的原因。 (如果不是事件的确切时间,至少得到一些事情发生的迹象)。



谢谢,
Maxim。

解决方案

跟踪GC活动将其添加到java命令:


-verbose:gc
-XX:+ PrintGCTimeStamps
-XX:+ PrintGCDetails


得到可能你传递空值。


java version "1.5.0_14"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
Java HotSpot(TM) Server VM (build 1.5.0_14-b03, mixed mode)

I'm trying to debug a NullPointerException I'm getting for passing a reference to statically defined field. To be more specific, I'm setting a global on a Drools3 working memory instance.

workingMemory.setGlobal("log", workingMemorieslog);

My assumption is that the Class where the field is statically defined is being garbage collected. (The receiving class must be using WeakReference or something like that, I don't really know)

How would you suggest to debug this? I think that if I could know exactly when JVM's GC unloads a class / instance of a class then I could narrow down on the cause of the buggy behavior. (If not the exact time of the event at least getting an indication that something did happened).

Thank you, Maxim.

解决方案

To trace GC activity add this to java command:

-verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails

NPE that you are getting is probably you passing null value.

这篇关于如何打印java类垃圾回收事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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