srini said:
Does anyone know how to create thread dumps from a java program? This
program will call another program that creates some threads and
attempt to do a thread dump except I'm not sure how to do it.
Any help would be appreciated.
Thanks,
Srini
------- I use this ----------
// Show active threads
public class MyThreads
{
private static int cnt = 0;
public static void display()
{
Thread[] myThreadList = new Thread[30];
// parent thread group of this thread group should be 'system'
int tcount =
Thread.currentThread().getThreadGroup().getParent().enumerate(myThreadList,
true);
String tcurrent = Thread.currentThread().getName();
System.out.println("Thread Group: " +
Thread.currentThread().getThreadGroup().getParent().getName());
String s = "------ " + (++cnt);
for (int i = 0; i < tcount; i++)
{
String tname = myThreadList
.getName();
boolean isd = myThreadList.isDaemon();
String tprio = String.valueOf(myThreadList.getPriority());
if (tprio.length() == 1)
{
tprio += " ";
}
if (myThreadList.isDaemon())
s += "\r\nThread " + i + ": d";
else
s += "\r\nThread " + i + ": ";
if (tname.equals(tcurrent))
s += "* " + tprio + " " + tname;
else
s += " " + tprio + " " + tname;
}
System.out.println(s);
}
}