Taking Thread dumps on Tomcat on windows
Sometime we start facing problems with Tomcat abrupt hang problem.The threads never go anywhere near the max. The
CPU usage never goes above high usage. The memory does not get used up. simply making the situation hang on server.
In that case only thing left with us is to analyse the thread dumps. Taking thread dumps is very easy on windows using jstack command. Only thing we need to do is to take process id and fetch the thread dumps, By default all logs redirects to catalina.log but we can force the logs to some external files using dos command.
Follow the Below steps to fetch the Threads Dumps on Tomcat,
Step 1: Press the ctrl+alt+del(task manager) and get the Tomcat process id from running processes list. If PID is not coming then simply click on view->select columns -> select the PID(Process identifier).
Step 2: Open the command console and type the below command
jstack -l e.g jstack -l 2268
After that you will see the thread dumps on the Tomcat console itself. If you want to redirect the logs to some external file then use the below command.
jstack -l e.g jstack -l 2268 > c:\tomcat_threads.log (make sure this file should be created first)
There is also one more workaround to fetch the same. Just set the focus on the tomcat console and press ctrl+break, you will see the same output on the console.
To read the Thread dumps, simply use the Samurai the one of best tool to analyse the thread dumps.
Hope this Helps.