• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

find out the invoking method

 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

i'm debugging a multi-threaded application. from my log output i can see that i'm creating a certain object at least one time too often. stepping through the code didn't reveal me the error yet.

i'm wondering if there is a way to log in the object's constructor where the invoking action came from. a simple "find usage" didn't help me, the code is too complicated. well, it's not really complicated, but as a matter of fact i cannot see this stupid call yet. :-)

many thanks for any help,
jan
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd either insert a

Thread.dumpStack();

in the constructor, or use a debugger and set a breakpoint inside it.

Does that help?
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perfectly... thx!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that if you want to log the info using something a little more refined than a dump to standard output, you can also use something like this:

or if you want to more easily extract specific info from the trace, use

Note that these are not guaranteed to always provide the stack trace (the API allows these methods to return incomplete info), but they susually work. And in performance-critical sections of code you may find that creating a new Throwable is fairly expensive. But as always with performance questions, the questino is, expensive to what? And does it really matter? Most code is not particularly performance-critical, and most of the time the effect of creating a new Throwable is virtually unnoticeable. But sometimes it's a problem. Just something to be aware of if you find your app is running too slowly - use a profiler to find out where the problem really is. I'm just saying the new Throwable() may cause a problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic