invoke close method after crawler is finished
@@ -373,6 +373,7 @@ public class WebFsIndexHelper {
int startedCrawlerNum = 0;
int activeCrawlerNum = 0;
+ try {
while (startedCrawlerNum < crawlerList.size()) {
// Force to stop crawl
if (systemHelper.isForceStop()) {
@@ -410,18 +411,24 @@ public class WebFsIndexHelper {
while (!finishedAll) {
finishedAll = true;
for (int i = 0; i < crawlerList.size(); i++) {
- crawlerList.get(i).awaitTermination(crawlingExecutionInterval);
- if (crawlerList.get(i).getCrawlerContext().getStatus() == CrawlerStatus.DONE
- && !Constants.DONE.equals(crawlerStatusList.get(i))) {
+ final Crawler crawler = crawlerList.get(i);
+ crawler.awaitTermination(crawlingExecutionInterval);
+ if (crawler.getCrawlerContext().getStatus() == CrawlerStatus.DONE && !Constants.DONE.equals(crawlerStatusList.get(i))) {
crawlerStatusList.set(i, Constants.DONE);
- final String sid = crawlerList.get(i).getCrawlerContext().getSessionId();
+ final String sid = crawler.getCrawlerContext().getSessionId();
indexUpdater.addFinishedSessionId(sid);
+ try {
+ crawler.close();
+ } catch (final Exception e) {
+ logger.warn("Failed to close the crawler.", e);
+ }
}
if (!Constants.DONE.equals(crawlerStatusList.get(i))) {
finishedAll = false;
}
}
}
+ } finally {
crawlerList.forEach(crawler -> {
try {
crawler.close();
@@ -429,6 +436,7 @@ public class WebFsIndexHelper {
logger.warn("Failed to close the crawler.", e);
}
});
+ }
crawlerList.clear();
crawlerStatusList.clear();
