java 打印垃圾回收,如何打印java类垃圾回收事件?

本文探讨了在遇到NullPointerException,特别是在涉及静态字段传递时如何进行调试的问题。作者怀疑可能是由于类被垃圾收集导致的,希望能追踪到JVM的垃圾收集活动以定位问题。通过在Java命令行中添加-verbose:gc, -XX:+PrintGCTimeStamps和-XX:+PrintGCDetails选项可以监控GC行为。此外,还提到了NPE可能是由于传递了null值导致的。
摘要由CSDN通过智能技术生成

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值