Created
July 1, 2011 12:03
-
-
Save cwilper/1058407 to your computer and use it in GitHub Desktop.
Java utility class for doing in-VM thread dumps. Was useful for tracking down the cause of FCREPO-946.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
/** | |
* Static methods for dumping current thread names, states, and stack | |
* traces, in the context of the currently executing JVM. | |
*/ | |
public class ThreadDumper { | |
public static void dump(String name) { | |
dump(name, false); | |
} | |
public static void dump(String name, boolean stackTrace) { | |
System.out.println("[Thread Dump " + name + "]"); | |
Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces(); | |
for (Map.Entry<Thread, StackTraceElement[]> entry: map.entrySet()) { | |
Thread thread = entry.getKey(); | |
System.out.println(" " + thread.getName() + " (" + thread.getState() + ")"); | |
if (stackTrace) { | |
for (StackTraceElement e: entry.getValue()) { | |
System.out.println(" " + e.toString()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment