为了争论,假设我正在为一个不可取消的任务实现 Future
。 Java 6 API doc说:
After [
cancel()
] returns, subsequent calls toisDone()
will always returntrue
.[
cancel()
] returnsfalse
if the task could not be cancelled, typically because it has already completed normally
它还说:
[
isDone()
] returnstrue
if this task completed.
但是,如果我的取消失败不是因为任务已经完成,而是因为它根本无法取消怎么办?有没有办法解决这个矛盾(除了让我的不可取消的任务可取消并完全回避它)?
最佳答案
看起来文档应该说
After
cancel()
returns true, subsequent calls toisDone()
...
Javadocs 通常是完全错误和矛盾的,即使在 10 年后,Sun 也常常懒得修复它们。仔细测试应该始终补充文档。
关于java - java.util.concurrent.Future 不一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2967303/