Skip to content

Commit 5412731

Browse files
SpiderStatus中getPagePerSecond()方法,增加验证逻辑,避免空指针,避免除数为零。
1 parent ab6ff7f commit 5412731

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

webmagic-extension/src/main/java/us/codecraft/webmagic/monitor/SpiderStatus.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ public Date getStartTime() {
8484

8585
@Override
8686
public int getPagePerSecond() {
87-
int runSeconds = (int) (System.currentTimeMillis() - getStartTime().getTime()) / 1000;
88-
return getSuccessPageCount() / runSeconds;
87+
if (getStartTime() != null) {
88+
int runSeconds = (int) (System.currentTimeMillis() - getStartTime().getTime()) / 1000;
89+
if (runSeconds != 0) {
90+
return getSuccessPageCount() / runSeconds;
91+
}
92+
}
93+
return -1;
8994
}
9095

9196
}

0 commit comments

Comments
 (0)