unix script to collect the thread dump logs of a process

6k views Asked by At

I am trying to generate an issue regarding HashMap.put function.I have written a test code which will run more than 100 threads.. by using jstack or kill I'am able to get the thread dump of a particular thread of my process..The problem is I can not capture the thread dump immediately, I want all the thread dumps to be logged in a file until the process ends.Is there any linux command or shell script that can write to do this?

1

There are 1 answers

0
Lokesh Gupta On
#!/bin/bash

if [ $# -eq 0 ]; then
    echo >&2 "Usage: jstackSeries  [ <count> [ <delay> ] ]"
    echo >&2 "    Defaults: count = 10, delay = 1 (seconds)"
    exit 1
fi

pid=$1          # required
count=${2:-10}  # defaults to 10 times
delay=${3:-1} # defaults to 1 second

while [ $count -gt 0 ]
do
    jstack $pid >jstack.$pid.$(date +%H%M%S.%N)
    sleep $delay
    let count--
    echo -n "."
done

refer here:

http://howtodoinjava.com/2012/12/19/how-to-get-thread-dump-in-linux-using-jstack/