Suppose there is some class method. Is it possible directly from the code of this method to find out which thread enters it?

threaddump interested in software, and not in debug threaddump development environments.

    1 answer 1

    Yes you can.

    In order to get the current thread, all you have to do is call the thread's static currentThread() method For example, the code:

     Thread currentThread = Thread.currentThread(); System.out.println(currentThread.getName()); System.out.println(currentThread.getPriority()); 

    Displays the name of the current thread and its priority to the console.