Skip to content

Commit a2bbd6d

Browse files
committed
clean code
1 parent 7d3cf1a commit a2bbd6d

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

docs/java.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ show-busy-java-threads.sh -a <输出记录到的文件>
6464
# 记录到文件以方便回溯查看
6565

6666
show-busy-java-threads.sh <重复执行的间隔秒数> [<重复执行的次数>]
67-
# 多次执行,类似vmstat行为
67+
# 多次执行;这2个参数的使用方式类似vmstat命令
6868

6969
##############################
7070
# 注意:
@@ -91,9 +91,9 @@ Options:
9191
-s, --jstack-path <path> specify the path of jstack command
9292
-F, --force set jstack to force a thread dump(use jstack -F option)
9393
-h, --help display this help and exit
94-
delay the delay between updates in seconds.
95-
count the number of updates.
96-
the usage of delay/count imitates vmstat
94+
delay the delay between updates in seconds
95+
count the number of updates
96+
delay/count arguments imitates style of vmstat command
9797
```
9898
9999
### 示例
@@ -148,7 +148,7 @@ $ show-busy-java-threads.sh
148148
- 发现并解决`jstack`非当前用户`Java`进程的问题。 [#50](https://github.com/oldratlee/useful-scripts/pull/50)
149149
- 优化性能,通过`read -a`简化反复的`awk`操作。 [#51](https://github.com/oldratlee/useful-scripts/pull/51)
150150
- [superhj1987](https://github.com/superhj1987) / [lirenzuo](https://github.com/lirenzuo)
151-
- 提供/实现多次执行的功能 [superhj1987/awesome-scripts#1](https://github.com/superhj1987/awesome-scripts/issues/1)
151+
- 提出/实现了多次执行的功能 [superhj1987/awesome-scripts#1](https://github.com/superhj1987/awesome-scripts/issues/1)
152152
153153
:beer: [show-duplicate-java-classes](../show-duplicate-java-classes)
154154
----------------------

show-busy-java-threads.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# @author Jerry Lee
99
# @author superhj1987
1010

11-
readonly PROG=`basename $0`
11+
readonly PROG="`basename $0`"
1212
readonly -a COMMAND_LINE=("$0" "$@")
1313

1414
# Get corrent current user name via whoami command
@@ -17,8 +17,7 @@ readonly -a COMMAND_LINE=("$0" "$@")
1717
readonly USER="`whoami`"
1818

1919
usage() {
20-
local out
21-
[ -n "$1" -a "$1" != 0 ] && out=/dev/stderr || out=/dev/stdout
20+
[ -n "$1" -a "$1" != 0 ] && local out=/dev/stderr || local out=/dev/stdout
2221

2322
> $out cat <<EOF
2423
Usage: ${PROG} [OPTION]... [delay [count]]
@@ -37,9 +36,9 @@ Options:
3736
-s, --jstack-path <path> specify the path of jstack command
3837
-F, --force set jstack to force a thread dump(use jstack -F option)
3938
-h, --help display this help and exit
40-
delay the delay between updates in seconds.
41-
count the number of updates.
42-
the usage of delay/count imitates vmstat
39+
delay the delay between updates in seconds
40+
count the number of updates
41+
delay/count arguments imitates style of vmstat command
4342
EOF
4443

4544
exit $1
@@ -124,7 +123,7 @@ normalPrint() {
124123
}
125124

126125
if [ -n "$jstack_path" ]; then
127-
! [ -x "$jstack_path" ] && {
126+
[ ! -x "$jstack_path" ] && {
128127
redPrint "Error: $jstack_path is NOT found/executalbe!" 1>&2
129128
exit 1
130129
}
@@ -136,11 +135,11 @@ else
136135
redPrint "Error: jstack not found on PATH! Use -s option set jstack path manually." 1>&2
137136
exit 1
138137
}
139-
! [ -f "$JAVA_HOME/bin/jstack" ] && {
138+
[ ! -f "$JAVA_HOME/bin/jstack" ] && {
140139
redPrint "Error: 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." 1>&2
141140
exit 1
142141
}
143-
! [ -x "$JAVA_HOME/bin/jstack" ] && {
142+
[ ! -x "$JAVA_HOME/bin/jstack" ] && {
144143
redPrint "Error: jstack not found on PATH and \$JAVA_HOME/bin/jstack($JAVA_HOME/bin/jstack) is NOT executalbe! Use -s option set jstack path manually." 1>&2
145144
exit 1
146145
}
@@ -210,5 +209,5 @@ for ((i = 0; update_count <= 0 || i < update_count; ++i)); do
210209
[ -z "${pid}" ] &&
211210
awk '$4=="java"{print $0}' ||
212211
awk -v "pid=${pid}" '$1==pid,$4=="java"{print $0}'
213-
} | sort -k5 -r -n | head --lines "${count}" | printStackOfThreads
212+
} | sort -k5 -r -n | head -n "${count}" | printStackOfThreads
214213
done

0 commit comments

Comments
 (0)