@Override public Void call() throws Exception { String baseUrl = PropertyHandler.getInstance().getValue("baseUrl"); String urlPageSuffix = PropertyHandler.getInstance().getValue("urlPageSuffix"); String numberOfPages = PropertyHandler.getInstance().getValue("numberOfPages"); String tagToParse = PropertyHandler.getInstance().getValue("tagToParse"); assert (numberOfPages.matches("^-?\\d+$")); // make sure someone supplied only numbers Elements headlines = null; int goal = Integer.parseInt(numberOfPages); try { for (int i = 0; i < goal; i++) { String url = baseUrl + urlPageSuffix + i; headlines = fetchContent(url, tagToParse); Spliterator<Element> elementSpliterator = headlines.spliterator().trySplit(); elementSpliterator.forEachRemaining( headline -> { try { if (!headline.text().toLowerCase().contains("permalink")) { logger.info("Produced: " + headline); queue.put(headline); } } catch (InterruptedException e) { e.printStackTrace(); } }); Thread.sleep(1000); } this.queue.continueProducing = Boolean.FALSE; System.out.println("Producer finished its job; terminating."); } catch (Exception ex) { ex.printStackTrace(); } return null; }