Skip to content

Commit ab6ff7f

Browse files
committed
Revert "pageCount修改"
This reverts commit 9a71f0a.
1 parent 30daec4 commit ab6ff7f

File tree

1 file changed

+4
-5
lines changed
  • webmagic-core/src/main/java/us/codecraft/webmagic

1 file changed

+4
-5
lines changed

webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.concurrent.TimeUnit;
2525
import java.util.concurrent.atomic.AtomicInteger;
2626
import java.util.concurrent.atomic.AtomicLong;
27-
import java.util.concurrent.atomic.LongAdder;
2827
import java.util.concurrent.locks.Condition;
2928
import java.util.concurrent.locks.ReentrantLock;
3029

@@ -103,7 +102,7 @@ public class Spider implements Runnable, Task {
103102

104103
private List<SpiderListener> spiderListeners;
105104

106-
private final LongAdder pageCount = new LongAdder();
105+
private final AtomicLong pageCount = new AtomicLong(0);
107106

108107
private Date startTime;
109108

@@ -324,7 +323,7 @@ public void run() {
324323
onError(request);
325324
logger.error("process request " + request + " error", e);
326325
} finally {
327-
pageCount.increment();
326+
pageCount.incrementAndGet();
328327
signalNewUrl();
329328
}
330329
}
@@ -336,7 +335,7 @@ public void run() {
336335
if (destroyWhenExit) {
337336
close();
338337
}
339-
logger.info("Spider {} closed! {} pages downloaded.", getUUID(), pageCount.sumThenReset());
338+
logger.info("Spider {} closed! {} pages downloaded.", getUUID(), pageCount.get());
340339
}
341340

342341
protected void onError(Request request) {
@@ -651,7 +650,7 @@ public boolean isSpawnUrl() {
651650
* @since 0.4.1
652651
*/
653652
public long getPageCount() {
654-
return pageCount.sum();
653+
return pageCount.get();
655654
}
656655

657656
/**

0 commit comments

Comments
 (0)