The following code is from AbstractExecutorService:
/**
* Returns a <tt>RunnableFuture</tt> for the given callable task.
*
* @param callable the callable task being wrapped
* @return a <tt>RunnableFuture</tt> which when run will call the
* underlying callable and which, as a <tt>Future</tt>, will yield
* the callable's result as its result and provide for
* cancellation of the underlying task.
* @since 1.6
*/
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
return new FutureTask<T>(callable);
}
I fail to see why the class of the returned object from newTaskFor() would be called RunnableFuture instead of CallableFuture? What am I missing here ?
RunnableFuturerepresents a specific concept : a future result whose computation can be explicitly performed by a worker thread by callingrun().Since worker threads are usually not interested in the results of the computations they perform, they use
run()that doesn’t return the results. And threads that are interested in these results can obtain them fromget()as soon as the worker thread finished the computation.