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