I have a SpringBoot Scheduler which is executed every 1 sec. The scheduler throws InterruptedException . Now ,this scheduler often stops working and then gets restarted automatically after few minutes. The InterruptedException is not handled anywhere in the code. So ,can this be the reason of the scheduler stopping? If yes , how can this exception be handled? Below is the code snippet-
@Scheduled(fixedRateString = "${OUTBOUND_MESSAGE_CHK_SCHEDULE_FREQUENCY}")
public void fetchOutBoundMessages() throws InterruptedException{
log.debug("fetchOutBoundMessages started>>");
if(LockHolder.hasValidLock()){
log.debug("Fetching Outbound message for >>>>>>>>>");
JSONArray jsonArrayObj= service.putOutBoundService(boroCode);
}
else {
log.info("Lock has not available..");
}
}```
InterruptedExceptionis an exception that gets thrown by Java synchronization primitives when the thread they are waiting in gets interrupted from another thread via theThread.interruptmethod. TheThread.interruptmethod is the Java way for gracefully cancelling concurrent tasks.In your case it means that the method
fetchOutBoundMessageswas waiting on a lock of some sort and there was a thread in your system that for some reason decided to callinterrupton the thread runningfetchOutBoundMessages.Maybe try to set a breakpoint on
Thread.interruptto see who does that and why.