Sign up to get Free Ebooks...

I hope you enjoy reading this article. If you are looking for such article ,Click here


How to Collect JStack in Linux using 2 different ways?

  • Home
  • /
  • Blog
  • /
  • How to Collect JStack in Linux using 2 different ways?

Jstack  is one of the most important tools when trying to figure out what a java process is doing apart from looking at the logs. It has to be used in conjunction with jps in order to give it a process id. It shows a list of threads, each one has a name, and they appear in the order that they were created.

In order to take a jstack you can perform following steps- 

Step 1: Get the PID of your java process

# ps -elf | grep java_process

Step 2: Request a Thread Dump from the JVM. Assuming jstack is in the path

# jstack -F <procees_id> > jstack1.out 
wait 5 minutes and take another one 
# jstack -F <procees_id> > jstack2.out 

Script for collecting jstack

#!/bin/sh
#
# Takes the PID as an argument. 
# Make sure you set JAVA_HOME
#
# Create thread dumps a specified number of times (i.e. LOOP) and INTERVAL. 
#
# Thread dumps will be collected in the file "jstack_threaddump.out", in the same directory from where this script is been executed.
#
# Usage: sh ./threaddump_linux_jstack-continuous.sh <JBOSS_PID>
#
# Number of times to collect data.
LOOP=6
# Interval in seconds between data points.
INTERVAL=20
# Setting the Java Home, by giving the path where your JDK is kept
JAVA_HOME=/home/jdk1.6.0_21
for ((i=1; i <= $LOOP; i++))
do
$JAVA_HOME/bin/jstack -l $1 >> jstack_threaddump.out
echo "thread dump #" $i
if [ $i -lt $LOOP ]; then
echo "sleeping..."
sleep $INTERVAL
fi
done


November 11, 2024

November 11, 2024

November 11, 2024

June 19, 2023

May 31, 2023

May 9, 2023

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>