Skip to content

Commit 4d0cdb0

Browse files
niuxiaozuniuxiaozu
and
niuxiaozu
authored
stopWhenComplete,增加动态修改完成时停止方法。 (#1169)
Co-authored-by: niuxiaozu <[email protected]>
1 parent 49a5eff commit 4d0cdb0

File tree

1 file changed

+8
-1
lines changed
  • webmagic-core/src/main/java/us/codecraft/webmagic

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class Spider implements Runnable, Task {
8585

8686
protected AtomicInteger stat = new AtomicInteger(STAT_INIT);
8787

88-
protected boolean exitWhenComplete = true;
88+
protected volatile boolean exitWhenComplete = true;
8989

9090
protected final static int STAT_INIT = 0;
9191

@@ -598,6 +598,13 @@ public void stop() {
598598
}
599599
}
600600

601+
/**
602+
* Stop when all tasks in the queue are completed and all worker threads are also completed
603+
*/
604+
public void stopWhenComplete(){
605+
this.exitWhenComplete = true;
606+
}
607+
601608
/**
602609
* start with more than one threads
603610
*

0 commit comments

Comments
 (0)