Thread.getAllStackTraces() has the following syntax.
public static Map < Thread , StackTraceElement []> getAllStackTraces()
In the following code shows how to use Thread.getAllStackTraces() method.
//from w w w. j a v a2 s .c o m import java.util.*; class ThreadDemo implements Runnable { public void run() { System.out.println("This is run() method"); } } public class Main{ public static void main(String args[]) { ThreadDemo trace = new ThreadDemo(); Thread t = new Thread(trace); // this will call run() method t.start(); // returns a map of stack traces Map m = Thread.getAllStackTraces(); } }
The code above generates the following result.