How to create a thread dump (aka. stacktrace dump) in Tomcat?

In a Linux/Unix environment send a QUIT signal to the JVM process.
Eg.
kill -QUIT <PID>

On a Windows server there's a utility named "Monitor Tomcat" in the Start Menu (under "Apache Tomcat ..." group. Start it, right-click its icon in the system tray and select "Thread dump". This will generate a dump in Tomcat's log directory with a filename like "jakarta_service_yyyymmdd.log".

Note: this will work only via the server console or through VNC. If you run it in a Terminal Services connection (via Remote Desktop client), you'll get a "The system cannot find the file specified. Unable to open the Event Mutex." error message. You can work around this if you connect to the Terminal Services console session (eg. in rdesktop it's the -0 option, in Microsoft's RDP client you've to run mstsc.exe with the /console option from the command line, etc.).

If you have only Terminal Services access to the server, but cannot connect to the console session, then you've still one more chance to get a thread dump.
  1. Stop the Tomcat NT service.
  2. Start up a command line (cmd.exe) and step into the Tomcat directory (eg. cd /d C:\Program Files\Tomcat 5.5)
  3. Set the JAVA_HOME variable to point to a proper JDK (eg. set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_06)
  4. Start Tomcat with the catalina.bat (and NOT the startup.bat!) using the run parameter and redirecting the output into a logfile (eg. bin\catalina.bat run >> ..\logs\jakarta_cmdline.log 2>&1)
  5. Check this logfile, wait until a line like "INFO: Server startup in ... ms" appears
  6. Reproduce the problem that you wanted to debug with generating a stacktrace
  7. Press CTRL+Break in the command window to generate the thread dump
The dump will be written in the logfile where you redirected the output of the JVM console. You can exit this Tomcat instance by pressing CTRL+C in the command prompt window.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

/console doesn't work anymore

For some reason beyond my ken, Microsoft, at some point, decided to start ignoring the /console command.

If /console isn't working for you, try mstsc /admin to get a tomcat thread dump to work through RDP.

http://frank.vanpuffelen.net/2009/04/mstsc-console-doesnt-work-anymore.html

Re: /console doesn't work anymore

Thanks for the feedback.

Syndicate content