What's the difference between Future and FutureTask in Java?

前端 未结 5 1799
迷失自我
迷失自我 2020-12-13 08:37

Since use ExecutorService can submit a Callable task and return a Future, why need to use FutureTask to wrap

5条回答
  •  天命终不由人
    2020-12-13 09:12

    Future is just interface. Behind the scene, the implementation is FutureTask.

    You can absolutely use FutureTask manually but you will lose the advantages of using Executor (pooling thread, limit the thread, etc). Using FutureTask is quite similar to using the old Thread and using the run method.

提交回复
热议问题