How to get method call stack information in java code

Hi,

I have a method a() in class A. I want to get the name of method and class which called method a. Is there any way of doing it ?

I tried using StackIntrospector from org.apache.log.util package, and it solves my purpose. Is the same thing possible using standard java API's without using any external API's ?

[333 byte] By [satyajit83a] at [2007-11-27 11:31:22]
# 1

Usually when I try something like this, I use a trick:

Throwable t = new Throwable();

StackTraceElement[] stackTrace = t.getStackTrace();

It's not nice but it works.

StephanTheNumba at 2007-7-29 16:39:18 > top of Java-index,Core,Core APIs...
# 2

> Usually when I try something like this, I use a

> trick:

>

> > Throwable t = new Throwable();

> StackTraceElement[] stackTrace = t.getStackTrace();

>

>

> It's not nice but it works.

StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();

Slightly more elegant, and saves the overhead of creating a new Throwable

If your code depends on this to execute, it may well be poorly designed, though

georgemca at 2007-7-29 16:39:18 > top of Java-index,Core,Core APIs...