Skip to content

Commit 6ea2193

Browse files
committed
! improve jstack search order
1 parent 3c042ba commit 6ea2193

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

bin/show-busy-java-threads

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,19 +310,33 @@ if [ -n "$store_dir" ]; then
310310
fi
311311

312312
################################################################################
313-
# check the existence of jstack command
313+
# search/check the existence of jstack command
314+
#
315+
# search order/priority:
316+
# 1. from -s option
317+
# 2. from under env var JAVA_HOME
318+
# 3. from under env var PATH
314319
################################################################################
315320

316321
if [ -n "$jstack_path" ]; then
317-
[ -f "$jstack_path" ] || die "$jstack_path is NOT found!"
318-
[ -x "$jstack_path" ] || die "$jstack_path is NOT executable!"
322+
# 1. check jstack_path set by -s option
323+
[ -f "$jstack_path" ] || die "$jstack_path (set by -s option) is NOT found!"
324+
[ -x "$jstack_path" ] || die "$jstack_path (set by -s option) is NOT executable!"
325+
elif [ -n "$JAVA_HOME" ]; then
326+
# 2. search jstack under JAVA_HOME
327+
if [ -f "$JAVA_HOME/bin/jstack" ]; then
328+
[ -x "$JAVA_HOME/bin/jstack" ] || die "found \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) is NOT executable!${nl}Use -s option set jstack path manually."
329+
jstack_path="$JAVA_HOME/bin/jstack"
330+
elif [ -f "$JAVA_HOME/../bin/jstack" ]; then
331+
[ -x "$JAVA_HOME/../bin/jstack" ] || die "found \$JAVA_HOME/../bin/jstack($JAVA_HOME/../bin/jstack) is NOT executable!${nl}Use -s option set jstack path manually."
332+
jstack_path="$JAVA_HOME/../bin/jstack"
333+
fi
319334
elif command -v jstack &>/dev/null; then
335+
# 3. search jstack under PATH
320336
jstack_path="$(command -v jstack)"
337+
[ -x "$jstack_path" ] || die "found $jstack_path from PATH is NOT executable!${nl}Use -s option set jstack path manually."
321338
else
322-
[ -n "$JAVA_HOME" ] || die "jstack not found on PATH and No JAVA_HOME setting! Use -s option set jstack path manually."
323-
[ -f "$JAVA_HOME/bin/jstack" ] || die "jstack not found on PATH and \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) file does NOT exists! Use -s option set jstack path manually."
324-
[ -x "$JAVA_HOME/bin/jstack" ] || die "jstack not found on PATH and \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) is NOT executable! Use -s option set jstack path manually."
325-
jstack_path="$JAVA_HOME/bin/jstack"
339+
die "jstack NOT found by JAVA_HOME(${JAVA_HOME:-not set}) setting and PATH!${nl}Use -s option set jstack path manually."
326340
fi
327341

328342
################################################################################

0 commit comments

Comments
 (0)