Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created October 29, 2020 09:28
Show Gist options
  • Save saswata-dutta/7ecf357f8df217b5ccbff6747f192be2 to your computer and use it in GitHub Desktop.
Save saswata-dutta/7ecf357f8df217b5ccbff6747f192be2 to your computer and use it in GitHub Desktop.
Periodically creates thread dump of a running java process to debug unresponsive/blocked threads
#!/bin/bash
# get process_id using jps -v or ps
# ps -mo pid.lwp.stime.time.cpu -C java
# your/path/to/jstack `ps aux | grep java | grep -v grep | awk '{print $2}'` >> threaddump.log
readonly process_id=${1}
readonly times=${2:-10}
readonly pause=${3:-10}
for((i=1;i<=$times;i++))
do
dump="threaddump_${i}"
jstack ${process_id} > ${dump}
echo "dumped to ${dump}"
sleep ${pause}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment