Skip to content

Commit 1d65a54

Browse files
committed
WIP
1 parent d5c9df6 commit 1d65a54

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

bin/show-busy-java-threads

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ readonly USER="`whoami`"
2121
################################################################################
2222

2323
# NOTE: $'foo' is the escape sequence syntax of bash
24-
readonly ec=$'\033' # escape char
24+
readonly ec=$'\033' # escape char
2525
readonly eend=$'\033[0m' # escape end
26+
readonly nl=$'\n' # new line
2627

2728
colorEcho() {
2829
local color=$1
@@ -246,21 +247,37 @@ if [ -n "$store_dir" ]; then
246247
fi
247248

248249
################################################################################
249-
# check the existence of jstack command
250+
# check/search the existence of jstack command
251+
#
252+
# search order/priority:
253+
# 1. -s option
254+
# 2. jstack command under env JAVA_HOME
255+
# 3. jstack command under env PATH
250256
################################################################################
251257

252258
if [ -n "$jstack_path" ]; then
253-
[ -f "$jstack_path" ] || die "$jstack_path is NOT found!"
254-
[ -x "$jstack_path" ] || die "$jstack_path is NOT executalbe!"
259+
# 1. check jstack_path set by -s option
260+
[ -f "$jstack_path" ] || die "$jstack_path (set by -s option) is NOT found!"
261+
[ -x "$jstack_path" ] || die "$jstack_path (set by -s option) is NOT executable!"
262+
elif [ -n "$JAVA_HOME" ]; then
263+
# 2. check jstack under JAVA_HOME
264+
if [ -f "$JAVA_HOME/bin/jstack" ]; then
265+
[ -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."
266+
jstack_path="$JAVA_HOME/bin/jstack"
267+
elif [ -f "$JAVA_HOME/../bin/jstack" ]; then
268+
[ -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."
269+
jstack_path="$JAVA_HOME/../bin/jstack"
270+
fi
255271
elif which jstack &> /dev/null; then
272+
# 3. check jstack under PATH
256273
jstack_path="`which jstack`"
257-
else
258-
[ -n "$JAVA_HOME" ] || die "jstack not found on PATH and No JAVA_HOME setting! Use -s option set jstack path manually."
259-
[ -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."
260-
[ -x "$JAVA_HOME/bin/jstack" ] || die "jstack not found on PATH and \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) is NOT executalbe! Use -s option set jstack path manually."
261-
jstack_path="$JAVA_HOME/bin/jstack"
262274
fi
263275

276+
if [ -n "$jstack_path" ]; then
277+
die "No JAVA_HOME setting, and jstack NOT found on PATH!${nl}Use -s option set jstack path manually."
278+
fi
279+
280+
264281
################################################################################
265282
# biz logic
266283
################################################################################

0 commit comments

Comments
 (0)