Java Utililty Methods Thread Dump

List of utility methods to do Thread Dump

Description

The list of methods to do Thread Dump are organized into topic(s).

Method

StringdumpStack(Thread t)
dump Stack
StackTraceElement e[] = t.getStackTrace();
if (e != null) {
    StringBuffer dump = new StringBuffer();
    for (int i = 0; i < e.length; i++) {
        dump.append("\n\t");
        dump.append(e[i].toString());
    return dump.toString();
...
voiddumpThreadGroup(ThreadGroup tg, StringBuffer sb)
Dump threads in threadgroup recursively.
if (tg != null) {
    try {
        if (tg.activeCount() == 0 && tg.activeGroupCount() == 0 && tg.isDestroyed() == false)
            tg.destroy();
    } catch (Throwable e) {
    sb.append("Group " + tg.getName());
    sb.append(",ac=" + tg.activeCount());
...
voiddumpThreads()
dump Threads
ThreadGroup group = Thread.currentThread().getThreadGroup();
int activeCount = group.activeCount();
Thread[] threads = new Thread[activeCount];
group.enumerate(threads);
System.out.println("Thread-Group " + group + " contains " + activeCount + " threads");
for (Thread thread : threads) {
    System.out.println("Thread " + thread);
voiddumpThreads()
dump Threads
ThreadGroup threadgroup1 = null;
for (ThreadGroup threadgroup = Thread.currentThread()
        .getThreadGroup(); threadgroup != null; threadgroup = threadgroup.getParent()) {
    threadgroup1 = threadgroup;
threadgroup1.list();