Making sure to call shutdown on strategy once the cache is interrupted.

This commit is contained in:
Sahil Palvia 2017-09-27 21:01:29 -07:00
parent 7b76d1d56e
commit cd1f944add

View file

@ -115,6 +115,7 @@ public class PrefetchGetRecordsCache implements GetRecordsCache {
while (true) {
if (Thread.currentThread().isInterrupted()) {
log.warn("Prefetch thread was interrupted.");
callShutdownOnStrategy();
break;
}
if (prefetchCounters.shouldGetNewRecords()) {
@ -129,8 +130,8 @@ public class PrefetchGetRecordsCache implements GetRecordsCache {
getRecordsResultQueue.put(processRecordsInput);
prefetchCounters.added(processRecordsInput);
} catch (InterruptedException e) {
log.info("Thread was interrupted, indicating shutdown was called on the cache. Calling shutdown on the GetRecordsRetrievalStrategy.");
getRecordsRetrievalStrategy.shutdown();
log.info("Thread was interrupted, indicating shutdown was called on the cache.");
callShutdownOnStrategy();
} catch (Error e) {
log.error("Error was thrown while getting records, please check for the error", e);
}
@ -138,6 +139,12 @@ public class PrefetchGetRecordsCache implements GetRecordsCache {
}
}
private void callShutdownOnStrategy() {
if (!getRecordsRetrievalStrategy.isShutdown()) {
getRecordsRetrievalStrategy.shutdown();
}
}
private void sleepBeforeNextCall() throws InterruptedException {
if (lastSuccessfulCall == null) {
return;