I've been searching web for a week now but none of the posts like How do I get FutureTask to return after TimeoutException? seems to answer my question. I've extracted a code sample from my code:
Future<Object> result = executorService.submit(new Callable<Object>() {
@Override public Object call() throws Exception {
...........
}
});
try {
return result.get(timeout.getValue(), timeout.getUnit().getTimeUnit());
} catch (TimeoutException e) {
result.cancel(true);
throw new TTimeoutException(e);
}
If I run this, sometimes(1 out of 1000) I'm getting
java.lang.InterruptedException
at java.util.concurrent.FutureTask.awaitDone(FutureTask.java:400)
at java.util.concurrent.FutureTask.get(FutureTask.java:199)
at com.abc.callers.A.call(A.java:83)
and line no:83 is result.get() of future task shown in above code sample.
Now my question is, can calling result.cancel(true) in future cause InterruptedException in result.get? If not, who can change the interrupt status of my current thread? AFAIK result.get() isn't the same thread as the one running my submitted task which I'm cancelling..