获取Java堆栈跟踪中涉及的对象 [英] Get objects involved in Java stacktrace

查看:387
本文介绍了获取Java堆栈跟踪中涉及的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 Thread.currentThread()。getStackTrace()来检索当前的堆栈跟踪,但是这只给出了调用中涉及的类。是否可以检索调用跟踪中涉及的对象实例?也许某种类型的库允许我从堆中检索对象?

I can retreive the current stacktrace using Thread.currentThread().getStackTrace() but this gives me only the classes involved in the call. 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?

我有一个问题需要我追溯到一个间接创建对象的Spring bean我正在请求堆栈跟踪。

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.

UPDATE
如果在Java中没有内置工具我正在搜索一个可嵌入的库,它可以在运行时为我做这件事。

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.

推荐答案

这是一个非常有趣的想法,但不幸的是整个<强>没有,你不能,这是不可能的。

It is a very interesting idea, but, unfortunately in whole no, you could not, it is impossible.

UPD:答案的原因之一不是这个事实,如果它可能,那么必须存在一些对所有创建对象的引用列表。但在这种情况下,Java GC根本不起作用。

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. But in this case Java GC would not work at all.

这篇关于获取Java堆栈跟踪中涉及的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆