GC overhead limit exceeded using while loop try catch

Viewed 24

Below is my code block where

  1. when interrupted exception is thrown it will be catched
  2. In catch block, if interrupt flag is reset using Thread.currentThread().interrupt(); then it shows the gc overhead limit.
  3. 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?

0 Answers
Related