How to dump stack from currently running threads
843810May 27 2003 — edited May 28 2003I have a multithreaded application that I am trying to debug. We have a telnet interface into this app, so that during runtime I can log in and issue certain commands to it. I have added a command to dump stacktraces from the threads, but it doesn't appear to work correctly. Here is the code that I use:
Thread th = Thread.currentThread();
ThreadGroup tg = th.getThreadGroup();
Thread[] ath = new Thread[tg.activeCount()];
tg.enumerate(ath);
for (int i=0; i < ath.length; i++){
if (ath.equals(th))
continue;
if (ath[i] != null)
ath[i].dumpStack();
}
When I look at ath after the tg.enumerate call it contains all of the threads that I am interested in. However when I call ath[i].dumpStack() it doesn't give me the trace from inside that thread, rather it gives me:
java.lang.Exception: Stack trace
at java.lang.Thread.dumpStack(Thread.java:993)
at com.haskovec.dbagent.Telnet.messageReceived(Telnet.java:206)
at com.haskovec.dbagent.TelnetRec.run(TelnetRec.java:52)
I get that trace for every running thread, and that is inside the telnet thread. Unfortunately I am not interested in this thread, but rather the trace from inside the running threads. Am I doing something wrong? Any suggestions on how to get the data that I am looking for.