简体   繁体   English

获取Java Stacktrace中涉及的对象

[英]Get objects involved in Java stacktrace

I can retreive the current stacktrace using Thread.currentThread().getStackTrace() but this gives me only the classes involved in the call. 我可以使用Thread.currentThread().getStackTrace()检索当前的堆栈Thread.currentThread().getStackTrace()但这只给我调用中涉及的类。 Is it possible to retreive the object instances involved in the call trace? 是否可以检索调用跟踪中涉及的对象实例? Maybe some kind of library which allows me to retreive the objects from the heap? 也许某种库可以让我从堆中检索对象?

I have a problem which requires me to trace back to a Spring bean which indirectly created the object where i'm requesting the stack trace. 我有一个问题,要求我追溯到Spring bean,该bean在我请求堆栈跟踪的地方间接创建了对象。

UPDATE If there's no builtin tool for this in Java i'm searching for an embeddable library which can do this for me in runtime. 更新如果Java中没有用于此的内置工具,我正在寻找可在运行时为我完成此工作的可嵌入库。

It is a very interesting idea, but, unfortunately in whole no , you could not, it is impossible. 这是一个非常有趣的想法,但不幸的是在整个 ,你不能,这是不可能的。

UPD: One of the reasons why answer is "no" is that fact, that if it could be possible, then some List of references to all created objects must exist. UPD:答案为“否”的原因之一是事实,即如果可能的话,必须存在对所有已创建对象的某些引用列表。 But in this case Java GC would not work at all. 但是在这种情况下,Java GC根本无法工作。

You may try housemd . 您可以尝试housemd It's developed by an engineer@alibaba and safe to be used even in a production environment, eg taobao.com. 它是由Engineer @ alibaba开发的,即使在生产环境中也可以安全使用,例如taobao.com。

Its feature include: 其功能包括:

 Display object field value Output invocation stack trace 

Following is an example screenshot: 以下是示例屏幕截图: 在此处输入图片说明

Try the Eclipse debugger in order to view the value of objects used in a particular method. 尝试使用Eclipse调试器以查看在特定方法中使用的对象的值。 Place breakpoints on the lines where you want to pause the program. 在要暂停程序的行上放置断点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM