I am having an interrupted exception in my code and I am trying to understand why.
What happens is that I am trying to create files in some place in my file system by calling FilesUtils.filesMethod().
If I get an IOException I try to sleep for 100 ms. During the sleep I need to check if I am interrupted (because InterruptedException is a check exception with sleep).
if so I print "Got interrupted" and get the interrupt flag of the current thread to true.
I am getting "Got interrupted" printed to my log.
Nowhere in my code there is the command interrput() to this thread.
what could it be?
could this senario makes sense:
the method of ilesUtils.filesMethod() throws InterruptedIOException because the stream was closed under the threads feets. Also this InterruptedIOException set the Interrupted flag to true.
I catch InterruptedIOException in my catch (IOException e).
The sleep checks if Interrupted flag is true. it is (see 1) so it throws InterruptedException.
could this be the case?
try {
FilesUtils.filesMethod();
break;
} catch (IOException e) {
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e1) {
log.info("Got interrupted", e1);
Thread.currentThread().interrupt();
}
}