Spring API throw interrupt signal when using Thread.sleep()

58 views Asked by At

I'm using Spring Boot to build my service. I have an API that will scan the database to update status. It follows:

  • Step 1: Scan the database to update status
  • Step 2: If have no data then sleep for 5 minutes then back to step 1

However, I don't know why when I sleep for 5 minutes, an interrupt exception is thrown and stops it. So, how can I avoid the interrupt signal, or how can I recover this thread when the exception is thrown?

This is my code:

public void update(String product, int status, List<String> type, int maxRetry, int size, double hours) { //NOSONAR

  do {
    try {
      list = repository.getList(status, product, type, hours, size);
      for (Data data: list) {
        // update data
      }
      entityManager.clear();
      if (list.isEmpty()) {
        // sleep 5 minutes
        Thread.sleep(300000);
      }
    } catch (InterruptedException e) { 
      log.error(e.getMessage(), e);
      Thread.currentThread().interrupt();
      break;
    }
  } while (obConfigService.isInWorkingHours());
}
0

There are 0 answers