aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "find out the invoking method" Watch "find out the invoking method" New topic
Author

find out the invoking method

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
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

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

Thread.dumpStack();

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
Wanderer
Sheriff

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: http://aspose.com/file-tools
 
subject: find out the invoking method
 
Similar Threads
Java 1.5 test Exercise 5-4 Sun Certified Programmer for Java 5
Confused...returning certain types
BADLY need GUI guide
Swing desktop application best practices
Inheritance when extending ArrayList of superclass? Help? :[