作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
应该怎样InterruptedException
在CountDownLatch.wait
等待期间处理?
我需要确定CountDownLatch.wait
会等待所有其他线程完成,但是如果在等待期间抛出异常,我应该如何处理?
最佳答案
首先方法是await()
,不是wait()
。 wait()
是来自 java.lang.Object 的方法,它执行完全不同的操作。
除非您决定从另一个线程中断 latch.await()
中被阻止的线程,否则您不会收到任何 InterruptedException。 (通过调用thread.interrupt()
)。而且既然你决定中断线程,那么你就应该知道当线程被中断时要做什么。通常,当您希望线程尽快完成正在做的事情并停止运行时,您会决定中断该线程。
关于java - 应如何处理 CountDownLatch.wait 的 InterruptedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15428938/
我是一名优秀的程序员,十分优秀!