When does Java's Thread.sleep throw InterruptedException? Is it safe to ignore it? I am not doing any multithreading. I just want to wait for a few seconds before retrying some operation.
+5
A:
You should generally NOT ignore the exception. Take a look at the following paper:
http://www.ibm.com/developerworks/java/library/j-jtp05236.html
Brandon E Taylor
2009-07-06 15:06:23
+1
A:
A solid and easy way to handle it in single threaded code would be to catch it and retrow it in a RuntimeException, to avoid the need to declare it for every method.
starblue
2009-07-06 15:13:59
+2
A:
The Java Specialists newsletter (which I can unreservedly recommend) had an interesting article on this, and how to handle the InterruptedException
. It's well worth reading and digesting.
Brian Agnew
2009-07-06 15:15:59