Monday, July 8, 2013

How to take Thread Dumps from a JVM

Step 1: Get the PID of your java process

The java JDK ships with the jps command which lists all java process ids.

You can run this command like this: jps –l

8112
1396 sun.tools.jps.Jps
3576 crx-quickstart\app\cq-quickstart-5.6.0-standalone.jar

Step 2 : Request a Thread Dump from the JVM

In windows:

1. Install cygwin to run shell script

2. set path to the environment variable list.

3. Add following script in the <name>.sh

#!/bin/bash
if [ $# -eq 0 ]; then
    echo >&2 "Usage: jstackSeries <pid> <run_user> [ <count> [ <delay> ] ]"
    echo >&2 "    Defaults: count = 10, delay = 0.5 (seconds)"
    exit 1
fi
pid=$1          # required
user=$2         # required
count=${3:-10}  # defaults to 10 times
delay=${4:-0.5} # defaults to 0.5 seconds
while [ $count -gt 0 ]
do
    jstack -F $pid >jstack.$pid.$(date +%H%M%S.%N)
    sleep $delay
    count=`expr $count - 1`
    echo -n "."
done

          4. You can run this shell script like:

               sh  <name>.sh <Process Id of AEM> <Intervals> <No.of Threads>

              Eg:  sh TrheadDump.sh  4321 10 5

              Result: It takes 5 thread dumps at an intervals of 10 sec.

Note: Running CQ on UNIX ?

           Reference: http://helpx.adobe.com/cq/kb/TakeThreadDump.html 

 

No comments:

Post a Comment