如何调试JVM资源加载?
要调试 JVM 中的类加载,我们可以使用参数 -verbose:class
,但是...有人知道如何调试资源加载(例如属性文件)吗?
To debug class loading in a JVM we can use the param -verbose:class
, but... Anyone knows how to debug resources loading (e.g. properties files)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我想您需要考虑使用分析器。 或者使用仪器接口的东西。
不确定它有多稳定,但是有 BTrace,它是 DTrace 的 Java 版本。
如果您在开发计算机上执行此操作,并且事件(正在加载的资源)数量不太频繁,您也可以在调试器中设置断点。
I suppose you need to look at using a profiler. Or something that uses the instrumentation interface.
Not sure how stable it is, but there is BTrace, which is kind of a Java version of DTrace.
If you are doing this on a development machine, and the number of events (resources being loaded) is not too frequent, you could also just set a breakpoint in the debugger.
资源以
URL
的形式提供。 因此,我想用“纯”Java 来实现:安装一个自定义的 ClassLoader,将URL
复制到具有自定义URLStreamHandler
的版本中。 将您的监控代码放入流处理程序中并转发到原始代码。Resources are provided as
URL
s. So, I guess to do it in "pure" Java: Install a customClassLoader
that copiesURL
s into a version with a customURLStreamHandler
. Put your monitoring code in the stream handler and forward to the original.您可以使用 InTrace 来检测执行加载的 Classloader 类。
对于 Sun JVM,我建议使用以下 Include 模式来跟踪适当的类:
You could use InTrace to instrument the Classloader classes which do the loading.
For the Sun JVM, I would suggest using the following Include patterns to trace appropriate classes:
在 Linux 环境中,您可以尝试:
它将为您提供一个列表,其中包含与指定 pid 关联的程序所使用的描述符。
更多信息
In a Linux environment you can try:
It will give you a list with the descriptors used by the program associated with the specified pid.
More Info
有几种技术可以调试类加载问题。 以下是 JRebel 创建者总结这些技术的精彩幻灯片:你真的得到类加载器吗?
There exist a couple of techniques to debug classloading problems. Here are good slides from the JRebel creators summarizing those techniques: Do you really get class loaders?