Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat thread dump

Tags:

Is there away to take a thread dump from Tomcat? I would like to monitor the threads running in Tomcat at a certain point in time.

Note: I was doing that on Web logic but i don't know how it can be done on Tomcat.

like image 673
Abdullah Avatar asked Sep 02 '13 12:09

Abdullah


People also ask

How do I dump a thread in Tomcat?

Execute the following to get the Tomcat threads dump: root@localhost:~# sudo -u $TOMCAT_USER $JAVA_HOME/bin/jstack -J-d64 -l $(ps aux | grep '[c]atalina' | awk '{print $2}') > ~/threads. log. Open the threads dump with IBM Thread & Dump Monitor Analyzer.

What is a thread dump?

A thread dump is a snapshot of the state of all threads that are part of the process. The state of each thread is presented with a so called stack trace, which shows the contents of a thread's stack. Some of the threads belong to the Java application you are running, while others are JVM internal threads.


3 Answers

If you use Linux, you can send a kill -3 [pid of your tomcat] and it will dump all current threads in the catalina.out.

like image 153
Julien Avatar answered Oct 29 '22 10:10

Julien


There is a simple way to monitor tomcat threads and do a dump. Start tomcat with the folowing java options :

-Dcom.sun.management.jmxremote.port=<some free port>
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false

After the tomcat is restarted you can simply start jconsole (part of jdk) or visualvm and create a new jmx connection to the port you have chosen above.
In both tools you also have an option to take a dump ;)

!!!But do that only in closed/secured environment - since there is no authentication set.!!!

like image 26
Patrik Bego Avatar answered Oct 29 '22 09:10

Patrik Bego


add java melody to your server https://code.google.com/p/javamelody/

it give you a lot of info including threads in runtime

like image 24
olexii Avatar answered Oct 29 '22 10:10

olexii