This article outlines how to create a script that can generate thread dumps automatically for a particular Java process. You can specify interval between each thread dump using this script.
#!/bin/bashparseArguments() { if [ $# -eq 0 ]; then echo >&1 "Run as appian : Usage: ongoing_threaddumps.sh <pid> <interval>" echo >&1 "Defaults: Interval = 30 (seconds)" exit 1 fi pid=$1 # required interval=${2:-30} # defaults to 30 seconds}captureThreaddump() { threaddumpsDir="appian_support_threaddumps/ongoing" mkdir -p ${threaddumpsDir} jstack -l $pid > ${threaddumpsDir}/threaddump_$(date -u +"%Y_%m_%d_%H_%M_%S").log}captureTopOutputAppServer() { threadInfoDir="appian_support_threaddumps/ongoing_topinfo" mkdir -p ${threadInfoDir} top -Hbn1 -p $pid > ${threadInfoDir}/threadinfo_$(date -u +"%Y_%m_%d_%H_%M_%S").log}main() { while true do sleep $interval captureThreaddump captureTopOutputAppServer done}### Begin script execution ###parseArguments $*main
chmod +x ongoing_threaddumps.sh
./ongoing_threaddumps.sh <java_process_pid> <interval> & disown
<java_process_pid>
<interval>
appian_support_threaddumps
./ongoing_threaddumps.sh 12345 10 & disown
kill -9 <script_pid>
This article applies to all versions of Appian.
Last Reviewed: September 2022