Wednesday, March 22, 2006

Generating Java Stack Trace

A Java stack trace displays the current state of each thread and monitor in a Java Virtual Machine. The stack trace displays the current method being executed by a thread. In addition the trace shows the sequence of calls leading up to the execution of the current method.

Analyzing stack traces can be very helpful in determine the causes of run time errors. For example if there is a deadlock detected, a stack trace can be generated to determine where the hang is occurring.

A Java stack trace can be generated by sending a signal to the JVM. On a UNIX environment this can be accomplished by sending a kill -3 to the Java process. It may be necessary to generate stack trace for several Java processes. The following can be used to send the kill signal to several Java processes:

for pid in `ps -u userid | grep java | awk '{print $1}'`;
do kill -3 $pid;
done

On Windows pressing the ctrl-break keys while having focus on the window where the Java process is running will generate the stack trace.

Sun's Java website provides an excellent article on analyzing stack traces.


Labels:

1 Comments:

Blogger Doug said...

hey,
It is a great article. Just stop by to say hello man.

7:59 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home