Clear interruption status after exiting consumer while loop
This commit is contained in:
parent
5108e98f38
commit
049f40a62e
@ -41,8 +41,8 @@ public class TbQueueConsumerTask {
|
||||
private CountDownLatch completionLatch;
|
||||
|
||||
public void setTask(Future<?> task) {
|
||||
this.task = task;
|
||||
this.completionLatch = new CountDownLatch(1);
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
public void subscribe(Set<TopicPartitionInfo> partitions) {
|
||||
@ -63,14 +63,14 @@ public class TbQueueConsumerTask {
|
||||
if (isRunning()) {
|
||||
try {
|
||||
if (!completionLatch.await(30, TimeUnit.SECONDS)) {
|
||||
task = null;
|
||||
throw new IllegalStateException("timeout of 30 seconds expired");
|
||||
}
|
||||
log.trace("[{}] Awaited finish", key);
|
||||
} catch (Exception e) {
|
||||
log.warn("[{}] Failed to await for consumer to stop", key, e);
|
||||
}
|
||||
task = null;
|
||||
}
|
||||
log.trace("[{}] Awaited finish", key);
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
@ -79,6 +79,7 @@ public class TbQueueConsumerTask {
|
||||
|
||||
public void finished() {
|
||||
completionLatch.countDown();
|
||||
task = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -237,7 +237,11 @@ public class TbRuleEngineQueueConsumerManager {
|
||||
log.info("[{}] Launching consumer", consumerTask.getKey());
|
||||
Future<?> consumerLoop = ctx.getConsumersExecutor().submit(() -> {
|
||||
ThingsBoardThreadFactory.updateCurrentThreadName(consumerTask.getKey().toString());
|
||||
consumerLoop(consumerTask.getConsumer());
|
||||
try {
|
||||
consumerLoop(consumerTask.getConsumer());
|
||||
} catch (Throwable e) {
|
||||
log.error("Failure in consumer loop", e);
|
||||
}
|
||||
consumerTask.finished();
|
||||
});
|
||||
consumerTask.setTask(consumerLoop);
|
||||
@ -262,7 +266,7 @@ public class TbRuleEngineQueueConsumerManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (consumer.isStopped()) {
|
||||
if (Thread.interrupted() || consumer.isStopped()) {
|
||||
consumer.unsubscribe();
|
||||
}
|
||||
log.info("Rule Engine consumer stopped");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user