My initial solution was to type something along the lines of jstack
$(jps | grep MyClass | cut -d ' ' -f 1).
That’s good but not great.
Instead, I came up with that simple script that I added before
$JAVA_HOME/bin in my
if [[ $1 =~ ^[a-zA-Z]+$ ]]
echo "# Trying to get thread dump of Java process with name '$1'"
pid=`jps | grep "$1" | cut -d ' ' -f 1`
echo $JAVA_HOME/bin/jstack $pid $@
$JAVA_HOME/bin/jstack $pid $@
echo "# Executing regular jstack"
Now I can use
It is a simple hack but I have found it very useful over the last months.
Even better, it does not prevent using regular jstack command-line parameters.