Either re-interrupt this method or rethrow the “InterruptedException issue in sonar

To “re-interrupt” as a best practice:

try{
    //some code
} catch (InterruptedException ie) {
    logger.error("InterruptedException: ", ie);
    Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
    logger.error("ExecutionException: ",ee);
}

Usually, when a thread is interrupted, whoever is interrupting the thread, wants the thread to exit what it’s currently doing.

However, make sure that you do NOT multi-catch:

catch (InterruptedException | ExecutionException e) {     
  logger.error("An error has occurred: ", e);
  Thread.currentThread().interrupt();
}

We do not want ExecutionException to be “re-interrupted”.

BONUS:
If you are interested, you can play with the examples here

Cheers

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)