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 ?
The point of a RunnableFuture is:
Future
Runnable
It converts the Callable you already have into something that is both a Future and a Runnable. It covers the exact use case it is intended to cover. If you have a Callable and need a Future, there's the FutureTask constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With