From 4d0cdb011fc42251c2476bb5f44379d588ae65f5 Mon Sep 17 00:00:00 2001 From: Niu_XZ Date: Mon, 17 Jun 2024 17:27:28 +0800 Subject: [PATCH] =?UTF-8?q?stopWhenComplete=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=BF=AE=E6=94=B9=E5=AE=8C=E6=88=90=E6=97=B6?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E6=96=B9=E6=B3=95=E3=80=82=20(#1169)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: niuxiaozu --- .../src/main/java/us/codecraft/webmagic/Spider.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java b/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java index 11a671f7..a35af70a 100644 --- a/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java +++ b/webmagic-core/src/main/java/us/codecraft/webmagic/Spider.java @@ -85,7 +85,7 @@ public class Spider implements Runnable, Task { protected AtomicInteger stat = new AtomicInteger(STAT_INIT); - protected boolean exitWhenComplete = true; + protected volatile boolean exitWhenComplete = true; protected final static int STAT_INIT = 0; @@ -598,6 +598,13 @@ public class Spider implements Runnable, Task { } } + /** + * Stop when all tasks in the queue are completed and all worker threads are also completed + */ + public void stopWhenComplete(){ + this.exitWhenComplete = true; + } + /** * start with more than one threads *