Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

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.

like image 295
NagyI Avatar asked Jan 15 '13 12:01

NagyI


1 Answers

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

like image 100
Andremoniy Avatar answered Sep 27 '22 16:09

Andremoniy