Utility of Future.cancel(boolean) method

后端 未结 4 1874
清歌不尽
清歌不尽 2020-12-08 04:24

I was simply exploring the java.util.concurrent package.

I learnt that the class \'Future\' has a method boolean cancel(boolean mayInterrupt

4条回答
  •  粉色の甜心
    2020-12-08 04:43

    Suppose, that the code that runs as part of your future does not support cooperative cancellation or interruption. Then cancelling an unstarted task is the best thing you can possibly do. That is why this method exists.

    In general I think of cancellation as strictly cooperative. Just cancelling some piece of code by force can lead to corrupted state.

提交回复
热议问题