1

I'd like to be notified when any class is created.

For example, I'd like to setup a listener like the following pseudocode:

addListener("onAnyClassCreated", myCallback);

public void function myCallback(Object obj)
{
  trace("obj was just created:" + obj.toString());
}

and then for any class created by the JVM for my app, the above "myCallback" function would be called. I could manage this for my own code, but I want it to work with any 3rd party libraries I'm using as well.

4

2 回答 2

1

您可能希望使用分析来计算某个类的实例,或者如果您真的想做您所描述的事情,可以使用一些检测工具来完成。例如字节曼

于 2013-06-01T22:13:18.953 回答
0

我认为您想要实现的目标可以通过远程监督您的 JVM 来完成。一种经典的方法是使用Java 管理扩展 (JMX)

您可以使用现有的 JMX 客户端,例如JConsoleVisualVM。如果您有特定需求,也可以创建自己的。

于 2013-06-01T22:16:36.090 回答