File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
webmagic-core/src/main/java/us/codecraft/webmagic/scheduler Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 1616 */
1717public class QueueScheduler extends DuplicateRemovedScheduler implements MonitorableScheduler {
1818
19- private BlockingQueue <Request > queue = new LinkedBlockingQueue <Request >();
19+ private final BlockingQueue <Request > queue ;
20+
21+ public QueueScheduler () {
22+ this .queue = new LinkedBlockingQueue <>();
23+ }
24+
25+ /**
26+ * Creates a {@code QueueScheduler} with the given (fixed) capacity.
27+ *
28+ * @param capacity the capacity of this queue,
29+ * see {@link LinkedBlockingQueue#LinkedBlockingQueue(int)}
30+ * @since 0.8.0
31+ */
32+ public QueueScheduler (int capacity ) {
33+ this .queue = new LinkedBlockingQueue <>(capacity );
34+ }
2035
2136 @ Override
2237 public void pushWhenNoDuplicate (Request request , Task task ) {
23- queue .add (request );
38+ try {
39+ queue .put (request );
40+ } catch (InterruptedException e ) {
41+ Thread .currentThread ().interrupt ();
42+ }
2443 }
2544
2645 @ Override
You can’t perform that action at this time.
0 commit comments