diff options
author | Brian Vosburgh | 2013-06-11 15:12:26 +0000 |
---|---|---|
committer | Brian Vosburgh | 2013-06-11 15:12:26 +0000 |
commit | ef79b68bfaa875bf7bf31e3a12577538950b7875 (patch) | |
tree | 91f1b294b16410c2701b0cc7ce432309d1bfa5c9 /common/plugins/org.eclipse.jpt.common.utility | |
parent | 17282e9b89cdf4cfb869a287cff326a30c6dafd9 (diff) | |
download | webtools.dali-ef79b68bfaa875bf7bf31e3a12577538950b7875.tar.gz webtools.dali-ef79b68bfaa875bf7bf31e3a12577538950b7875.tar.xz webtools.dali-ef79b68bfaa875bf7bf31e3a12577538950b7875.zip |
add various thread dump methods to SystemTools
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.utility')
-rw-r--r-- | common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SystemTools.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SystemTools.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SystemTools.java index bf29f05718..31fc69d61e 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SystemTools.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/SystemTools.java @@ -9,6 +9,9 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.internal; +import java.io.PrintStream; +import java.util.Map; + /** * Various system utility methods. * @see System#getProperty(String) @@ -156,6 +159,64 @@ public final class SystemTools { } + // ********** thread dump ********** + + /** + * Print all the current threads' stack traces on a string and return the + * resulting string. + * @see Thread#getAllStackTraces() + */ + public static String allThreadsToString() { + StringBuilder sb = new StringBuilder(5000); + dumpAllThreadsOn(sb); + return sb.toString(); + } + + /** + * Dump all the current threads' stack traces to the specified string + * builder. + * @see Thread#getAllStackTraces() + */ + public static void dumpAllThreadsOn(StringBuilder sb) { + Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces(); + for (Map.Entry<Thread, StackTraceElement[]> entry : stackTraces.entrySet()) { + sb.append(entry.getKey().getName()); + sb.append(StringTools.CR); + for (StackTraceElement element : entry.getValue()) { + sb.append(element); + sb.append(StringTools.CR); + } + sb.append(StringTools.CR); + } + } + + /** + * Dump all the current threads' stack traces to the + * {@link System#out system console}. + * @see Thread#getAllStackTraces() + */ + public static void dumpAllThreads() { + synchronized (System.out) { + dumpAllThreadsOn(System.out); + } + } + + /** + * Dump all the current threads' stack traces to the specified stream. + * @see Thread#getAllStackTraces() + */ + public static void dumpAllThreadsOn(PrintStream stream) { + Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces(); + for (Map.Entry<Thread, StackTraceElement[]> entry : stackTraces.entrySet()) { + stream.println(entry.getKey().getName()); + for (StackTraceElement element : entry.getValue()) { + stream.println(element); + } + stream.println(); + } + } + + // ********** constructor ********** /** |