Assuming we're in method2(), called by method1():
Thread.currentThread().getStackTrace() returns an array with StackTraceElements. The first element in it (array[0]) is the getStackTrace()-call, per se. The second (array[1]) is the enclosing method: method2(). And the third one (array[2]) describes the calling method: method1(). :-)
GO TO FULL VERSION