[concurrency-interest] what to do about InterruptedException inThreadPoolExecutor.awaitTermination

David Holmes dcholmes at optusnet.com.au
Tue Oct 17 20:31:11 EDT 2006


> My code looks something like:
> [code]
> exec.submitRunnable(imr);
> exec.shutdown();
> boolean finished= exec.awaitTermination(timeOut);
> [/code]
> I am trying to understand what should I do about the
> InterruptedException that can be thrown from the awaitTermination
> method. As I read in the JCiP, I should be doing one of:
> 1/ propagate it (which is not acceptable in my case)
> 2/ have something like Thread.currentThread().interrupt();
> 3/ ignore it

So the difference between #2 and #3 in practice is what else the thread
executing the above code does. In general you should always do #2 - it is
safe and correct no matter what thread does. #3 can be correct if the thread
does nothing else after the above code, but if you/someone changes that
later then they need to remember to convert to #2 if needed. So stick with
#2 as a general rule.

David Holmes

More information about the Concurrency-interest mailing list