在Java中处理InterruptedException以下处理方法的区别是什么?InterruptedException?做这件事最好的方法是什么?try{
//...} catch(InterruptedException e) {
Thread.currentThread().interrupt(); }或try{
//...} catch(InterruptedException e) {
throw new RuntimeException(e);}编辑:我还想知道这两种场景是在哪种情况下使用的。
3 回答

蛊毒传说
TA贡献1895条经验 获得超3个赞
传播 InterruptedException
-声明您的方法抛出检查 InterruptedException
这样你的来电者就得处理好了。 恢复中断
-有时你不能 InterruptedException
..在这种情况下,您应该捕获 InterruptedException
并通过调用 interrupt()
方法的 currentThread
因此,调用堆栈上的代码可以看到发出了一个中断。

茅侃侃
TA贡献1842条经验 获得超21个赞
InterruptedException
interrupt
Thread
Thread.currentThread().interrupt();
RuntimeException
添加回答
举报
0/150
提交
取消