Thread Dumps

S

srini

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
 
L

Liz

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);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top