Navigation Bar Staff Secure Home Products Partners Services Portfolio News Corporate Jobs Home
border image border image
transparent spacer image border image
transparent spacer image transparent spacer image transparent spacer image
Navigate Database Table: "WOFAQ"
Current record is #1 out of 21 in found set (21 total records in table)
List View    Search    Find All
<<First <Prev Next> Last>>

Question How do I get a stack trace / thread dump from a running java application? 
Answer

The short answer is: send the process the QUIT signal, or, under Java 1.5, use the jstack command.

The long answer:

Under Java 1.4, you first need to make sure that the thread dump goes someplace useful. Doing this requires changing the WO startup script -- called SpawnOfWotaskd.sh -- changing SpawnOfWotaskd.sh is generally a good idea even for Java 1.5, as it also helps in other situations, like when an app doesn't start properly.

If you're using Java 1.5 or you started the application from the command line, then skip to step 2. If you started the app automatically with JavaMonitor (which configures wotaskd to actually start the app), then you'll need to do some extra configuration.

Step 1: Edit wotaskd's App Launch Script

sudo emacs /System/Library/WebObjects/JavaApplications/wotaskd.woa/Contents/Resources/SpawnOfWotaskd.sh

Next, change the contents from this:

#!/bin/sh

$@ 1>/dev/null 2>&1 &

To this:

#!/bin/sh

$@ 1>>/tmp/woapplaunch.log 2>>/tmp/wothreaddump.log &

Now restart the instance from JavaMonitor.

Step 2: find the process ID

If you started the app from JavaMonitor, log into JavaMonitor and click the "Detail" button of the application you are interested in. This will list all running instances of the application. Note down the port number of the instance whose process ID is required. If you started the app from the command line, use the -WOPort argument to start up on a known port, or examine the log output to determine the dynamically assigned port.

In terminal on the server (or via ssh from your local machine) enter the following command:

ps -auxwww | grep <port number>
This will produce output as follows:

appserve 22869 0.0 -6.9 779104 144400 ?? S 8:56AM 4:09.90 java -XX:NewSize=2m -Xmx64m -Xms32m -DWORootDirectory=/System -DWOLocalRootDirectory= -DWOUserDirectory=/System/Library/WebObjects/JavaApplications/wotaskd.woa -DWOEnvClassPath= -DWOApplicationClass=com.foo.bar.Application -DWOPlatform=MacOS -Dcom.webobjects.pid=22869 -Xmx512m -Xms256m -classpath WOBootstrap.jar com.webobjects._bootstrap.WOBootstrap -WOPort 2020 -WOCachingEnabled YES -WODebuggingEnabled NO -WOOutputPath /Library/WebObjects/Logs/FooBarApp-1 -WOAutoOpenInBrowser NO -WOAutoOpenClientApplication NO -WOLifebeatInterval 30 -WOLifebeatEnabled YES -WOLifebeatDestinationPort 1085 -WOAdaptor WODefaultAdaptor -WOWorkerThreadCount 8 -WOListenQueueSize 128 -WOWorkerThreadCountMin 16 -WOWorkerThreadCountMax 256 -NSProjectSearchPath () -WOSessionTimeOut 3600 -WOApplicationName FooBarApp -WOMonitorEnabled YES -WONoPause YES

The number immediately after the first word ("appserve") is the process ID of the instance (in the above example the process ID is 22869).

Step 3: Send the QUIT Signal

This works on JDK 1.4 and later (and maybe earlier):

kill -QUIT <pid>

e.g. kill -QUIT 22869

The output will be:

  • in the console if you started from the command line
  • in /tmp/wothreaddump.log if you started from JavaMonitor / wotaskd (JDK 1.4)
  • in /tmp/woapplaunch.log if you started from JavaMonitor / wotaskd (JDK 1.5 / Leopard?)

OR

Step 3: Run jstack (Java 1.5 and later)

sudo jstack <process id>
Recent versions (at least on Leopard) of jstack do not show the correct thread names. You may find the kill -QUIT results more useful. 
Figure 1 No file available. 
Figure 2 No file available. 
Figure 3 No file available. 
Date Modified Aug 7 2009 
Modified By chill@global-village.net