This would be useful to analyze a root cause, when an application has suddenly stopped working or not responding . There could be a some kind of deadlock or waiting processes or something else.
JStack would help in getting the stack dump to a currently running java process.
JStack comes along with JDK kit, need not to install separately.
Go to command prompt, type below command with java process id.
To identify the java process id, you can 'jps' command.
>jps => this will list out the all java process id's.
5730 main => this is my java process id.
To get more details about which process ID belongs to which process use below command
> jps -ml
To get the additional information about the locks.
>jps -l <pid>
Jstack can also be used to get the thread dump for remotely running processes.
>jps <remote host name/ip address>
To write stack dump to a file:
>jstack -l 7840 > D:\Test\kklog.txt
">" is important to write into a file.
Some useful resources on this.