Thread dump programmatically /JDI (Java Debugger Interface)

There is a third way: Thread.getAllStackTraces()

http://java.sun.com/javase/6/docs/api/java/lang/Thread.html#getAllStackTraces()

This is much easier than the debugger interface...


You can get just about all the Thread info you need including deadlocks from http://java.sun.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html


Thread.getAllStackTraces() dumps only the execution trace of all the threads, but doesn't give the information of object locks that have been obtained by a particular thread or the lock on which a particular thread has been waiting. Basically, we'll not be able to nail down deadlocks with this.