File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes find out the invoking method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "find out the invoking method" Watch "find out the invoking method" New topic

find out the invoking method

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456

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,
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
I'd either insert a


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

Does that help?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
perfectly... thx!
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
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.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: find out the invoking method
jQuery in Action, 3rd edition