Back
Is there a way to get the name of the currently executing method in Java?
You can check out Thread.currentThread().getStackTrace() it will normally include the method you’re calling
For instance:
public Thread(ThreadGroup group, Runnable target, String name, long stackSize, boolean inheritThreadLocals)
public Thread(ThreadGroup group,
Runnable target,
String name,
long stackSize,
boolean inheritThreadLocals)
And here are a few lines from Java docs.
Some virtual machines may, under some circumstances, omit one or more stack frames from the stack trace. In the extreme case, a virtual machine that has no stack trace information concerning this thread is permitted to return a zero-length array from this method.
31k questions
32.8k answers
501 comments
693 users