使用JDI监听Java程序运行
Java虚拟机提供了一套用于调试(JVMDI)和监视(JVMPI)的接口,Java5之后统一为JVMTI: http://docs.oracle.com/javase/1.5.0/docs/guide/jvmti/?。
?
其中JVMDI分为三个部分:JVMDI,JDWP和JDI . http://docs.oracle.com/javase/1.4.2/docs/guide/jpda/architecture.html
?
这篇就是简单的介绍一下怎么使用JDI去监视程序的运行的。
?
首先假设有一个简单的程序:
?
最后看输出:
[JDI: EventSet: SUSPEND_EVENT_THREAD][JDI: Event: MethodEntryEvent@test.Test:23 in thread Thread-0][JDI: Event: BreakpointEvent@test.Test:23 in thread Thread-0]printHello was Entered!Reach Method printHello of test.Test[JDI: EventSet: SUSPEND_EVENT_THREAD]printHello was Entered![JDI: Event: MethodEntryEvent@test.Test:23 in thread Thread-0][JDI: Event: BreakpointEvent@test.Test:23 in thread Thread-0]Reach Method printHello of test.Test?
?