Welcome to

Confessions of a build breaker

A blog on Java, JEE and Spring by Jelmer Kuperus

What to do with an Interruptedexception

October 5th, 2007 by site admin

Many java methods, such as Thread.sleep and Process.waitFor can throw an Interruptedexception. InterruptedException is a checked exception and as such requires you to explicitly catch it. Up until recently I’ve always simply swallowed this exception. I was fairly confident that this was the proper way to deal with this exception because this is how I’d seen others handle it many times over. As it turns out I was wrong and this is the worst possible way to handle an interrupted exception

Brian Goetz of java concurrency in practice fame has written an article on the subject that is definitely worth a read

If there is anything you should take away from reading this article it is this :

“At the very least, whenever you catch InterruptedException and don’t rethrow it, reinterrupt the current thread before returning.”

Its interesting to see that even the spring guys initially got this wrong It was fixed in spring 1.2.8

Posted in java |

One Response

  1. Alef Arendsen Says:

    I saw a wonderful presentation by Heinz Kabuts last weekend that detailed this very approach. This was in Greece and he had his presentation titled ‘Top 10 laws of concurrency’. It also including the Law of Greek Driving, the Law of the Distracted Spear Fisherman’ and so on. If you ever get a chance to see this talk, please do so, it’s great :).

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

copyright © 2oo6 by Confessions of a build breaker | Powered by Wordpress

Ported by ThemePorter - template by Design4 | Sponsored by 47channel