Method 1: Use jstack utility from command line (part of the JDK distro).
Method 2: Send signal 3 to the java process, it will dump stack traces on stdout.
Method 3: Call Thread.getAllStackTraces () from within application:
public class StackTraceDumper
{
public static dumpAllStackTraces ()
{
for (Map.Entry <Thread, StackTraceElement []> entry:
Thread.getAllStackTraces().entrySet ())
{
System.out.println (entry.getKey ().getName () + ":");
for (StackTraceElement element: entry.getValue ())
System.out.println ("" + element);
}
}
}
Then use StackTraceDumper.dumpAllStackTraces()
where you need to dump stack traces.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…