Skip to content

Commit 0a7fc20

Browse files
committed
Fix division by zero error in TPS calculation (#507)
1 parent 07ba0a2 commit 0a7fc20

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

spark-common/src/main/java/me/lucko/spark/common/monitor/tick/SparkTickStatistics.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public void onTick(int currentTick) {
8181
}
8282

8383
long diff = now - this.last;
84+
if (diff <= 0) {
85+
// avoid division by zero
86+
return;
87+
}
88+
8489
BigDecimal currentTps = TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP);
8590
BigDecimal total = currentTps.multiply(new BigDecimal(diff));
8691

0 commit comments

Comments
 (0)