Created
May 31, 2017 01:01
-
-
Save kenwdelong/02e1a4cd26ef697cde77533002badaa5 to your computer and use it in GitHub Desktop.
Programmatic Thread Dump in Java
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
StringBuilder dump = new StringBuilder(); | |
ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean(); | |
ThreadInfo[] threadInfos = threadMxBean.getThreadInfo(threadMxBean.getAllThreadIds(), 150); | |
for(ThreadInfo info : threadInfos) | |
{ | |
dump.append('"').append(info.getThreadName()).append('"').append("\n"); | |
Thread.State state = info.getThreadState(); | |
dump.append(state); | |
StackTraceElement[] stes = info.getStackTrace(); | |
for(StackTraceElement ste : stes) | |
{ | |
dump.append("\n at ").append(ste); | |
} | |
dump.append("\n\n"); | |
} | |
System.out.println(dump.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment