This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Returns an array of stack trace elements representing the stack dump of this thread. This method will return a zero-length array if this thread has not started or has terminated. If the returned array is of non-zero length then the first element of the array represents the top of the stack, which is the most recent method invocation in the sequence. The last element of the array represents the bottom of the stack, which is the least recent method invocation in the sequence.
There is no guarantee that the stacktrace is available at all, though.
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
I'm curious why you want to do this. It seems to come up fairly often. If it's for profiling or out of curiosity, it might be ok. If you use the knowledge about the calling class for any logic you're wandering into a scary kind of coupling.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I've used it to implement job security. In some of my more complex classes -- ones I'm sure no one else can understand because they have methods with hundreds of lines and cryptic variables like x and cj -- I will occassionally look up the calling class's name. If it's a class written by a coworker that I don't particularly like, I'll pick a random number and return a incorrect result 1 out of 10 times.
This is just often enough to cause them heartache but not so frequent that they realize what's really going on. Most times they quit out of frustration, but even better if they're "let go" for incompetency.
Wait a minute, none of you know my coworkers, do you?
Just to be safe . . . For the humor impared, this is a joke.
Joined: Jan 29, 2003
Thanks, David. Gave me some good ideas. Now I need a runtime API into the source control system so I can see who last modified the calling class. If it was me, give good results.
I had brief contact with a mainframe COBOL CICS project across the hall many years ago that used the name of the calling program in logic all over the place. I dropped the source listing and ran.
Joined: Aug 31, 2002
This is where i plan to use this. In my Test Enviroment i want to configure my logging so that for certain error levels an email will be sent out with the log message after logging. I identify the develper to whom mail shld be sent by looking at the properties files which have the ClassName mapped to the programmer and programmer mapped to email.
Now in the logger i want to know which class actually made the call, to be able to look at the properties file to identify the programmer and his email.