Below is my code block where
- when interrupted exception is thrown it will be catched
- In catch block, if interrupt flag is reset using
Thread.currentThread().interrupt();then it shows the gc overhead limit. - If
Thread.currentThread().interrupt();is removed from catch program works fine.
void run()
while (this.isRunning()) {
try {
E element = ItemQueue.take();
consumer.accept(element);
} catch (Exception e) {
log.error("Error processing item in the queue: ", e);
Thread.currentThread().interrupt(); // if removed no gc overhead limit exceeded
}
}
}
Sonarqube gives bug message if this removed Thread.currentThread().interrupt(); as to handle the InterruptedException correctly, it should not be ignored
But it is an ideal practice to reset the interrupt flag when exception is catched, How to handle this situation?