ITeye博客

Good programming practice

共 1 篇文章

处理 InterruptedException(捕捉到它,然后怎么处理它?)

很多 Java™ 语言方法,例如 Thread.sleep() 和 Object.wait(),都可以抛出 InterruptedException。您不能忽略这个异常,因为它是一个检查异常(checked exception)。但是应该如何处理它呢?在本文中,并发专家 Brian Goetz 将解释 InterruptedException 的含义,为什么会抛出 InterruptedException,以及在捕捉到该异常时应该怎么做。 这样的情景您也许并不陌生:您在编写一个测试程序,程序需要暂停一段时间,于是调用 Thread.sleep()。但是编译器或 IDE 报错说没有处理检查到的…

2009-08-11 11:29 · Good programming practice · 应用服务器 · 游戏 · 活动 · IE · thread