Since use ExecutorService can submit a Callable task and return a Future, why need to use FutureTask to wrap Callable task and use the method execute? I feel they both do the same thing.
Since use ExecutorService can submit a Callable task and return a Future , why
Share
In fact you are correct. The two approaches are identical. You generally don’t need to wrap them yourself. If you are, you’re likely duplicating the code in AbstractExecutorService:
The only difference between Future and RunnableFuture, is the run() method:
A good reason to let the Executor construct the FutureTask for you is to ensure that there is no possible way more than one reference exists to the FutureTask instance. That is, the Executor owns this instance.