0

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?

Shog9
  • 156,901
  • 35
  • 231
  • 235
kiddo
  • 1,596
  • 7
  • 31
  • 60

1 Answers1

1
#!/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/

Lokesh Gupta
  • 463
  • 5
  • 8