File tree 2 files changed +29
-3
lines changed
src/main/java/edu/uci/ics/crawler4j/crawler
2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,11 @@ public class CrawlConfig {
123
123
*/
124
124
private boolean onlineTldListUpdate = false ;
125
125
126
+ /**
127
+ * Should the crawler stop running when the queue is empty?
128
+ */
129
+ private boolean shutdownOnEmptyQueue = true ;
130
+
126
131
/**
127
132
* If crawler should run behind a proxy, this parameter can be used for
128
133
* specifying the proxy host.
@@ -378,6 +383,17 @@ public boolean isFollowRedirects() {
378
383
public void setFollowRedirects (boolean followRedirects ) {
379
384
this .followRedirects = followRedirects ;
380
385
}
386
+
387
+ public boolean isShutdownOnEmptyQueue () {
388
+ return shutdownOnEmptyQueue ;
389
+ }
390
+
391
+ /**
392
+ * Should the crawler stop running when the queue is empty?
393
+ */
394
+ public void setShutdownOnEmptyQueue (boolean shutdown ) {
395
+ shutdownOnEmptyQueue = shutdown ;
396
+ }
381
397
382
398
public boolean isOnlineTldListUpdate () {
383
399
return onlineTldListUpdate ;
Original file line number Diff line number Diff line change 36
36
import edu .uci .ics .crawler4j .url .WebURL ;
37
37
import edu .uci .ics .crawler4j .util .IO ;
38
38
39
+ import org .slf4j .Logger ;
40
+ import org .slf4j .LoggerFactory ;
41
+
42
+ import java .io .File ;
43
+ import java .util .ArrayList ;
44
+ import java .util .List ;
45
+
39
46
/**
40
47
* The controller that manages a crawling session. This class creates the
41
48
* crawler threads and monitors their progress.
@@ -254,8 +261,11 @@ public void run() {
254
261
someoneIsWorking = true ;
255
262
}
256
263
}
257
- if (!someoneIsWorking ) {
258
- // Make sure again that none of the threads are alive.
264
+ boolean shut_on_empty = config .isShutdownOnEmptyQueue ();
265
+ if (!someoneIsWorking && shut_on_empty ) {
266
+ // Make sure again that none of the threads
267
+ // are
268
+ // alive.
259
269
logger .info ("It looks like no thread is working, waiting for 10 seconds to make sure..." );
260
270
sleep (10 );
261
271
@@ -511,4 +521,4 @@ public void shutdown() {
511
521
pageFetcher .shutDown ();
512
522
frontier .finish ();
513
523
}
514
- }
524
+ }
You can’t perform that action at this time.
0 commit comments