Whether method cancel() in java.util.concurrent.Future should be blocking?

懵懂的女人 提交于 2019-12-04 10:52:42

Do I understand something incorrectly?

I believe so. Future is not a job control API; it is an abstraction over the concept of a value which may not yet have been computed. By cancelling a Future you simply waive your interest in that value; the rest is up to implementation detail.

As a consequence, Future is not strongly coupled to the computation which will eventually produce its result. If you invoke cancel and it returns true, you have moved the Future to its final, unchangeable state: that of a cancelled Future, which will never produce its value. The underlying computation task may or may not go on for an indeterminate amount of time; you have no control over that through the Future's API.

I read it as "isCancelled() returns true after cancel() returned true" and I cannot see any inconsistences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!