Global Positioning System Reference
In-Depth Information
The main idea of a thread pool is to un-synchronize a large number of tasks
with different durations. Consequently, the executor framework decouples
a method call from a method return. From a logical point of view, an
application submits a task and can check on the result some time in the
future. The construct to fetch the result is the Future class.
The client call can be coded as
Callable<Object> getIdentity = new Callable<Object>()
{ @Override
public Object call() throws RemoteException
{ return remoteObject.getIdentity(); }};
and submitted with
Future<Object> taskResult
= executorService.submit( getIdentity );
Then, the executor services' submit method for Callable tasks organizes
a thread. Since the result is returned asynchronously, the method returns
a Future immediately. The application can use the waiting time to do
something else. The Future object supports different strategies to block
until the result is available, to wait a given time span, or to check on the
result or to cancel the task.
java.util.concurrent.Future<V>
A Future represents the result of an asynchronous compu-
tation. Methods are provided to check if the computation is
complete, to wait for its completion, and to retrieve the result
of the computation.
ˆ Vget(longtimeout,TimeUnitunit)
Waits if necessary for at most the given time for the com-
putation to complete, and then retrieves its result, if avail-
able.
ˆ Vget()
Waits if necessary for the computation to complete, and
then retrieves its result.
ˆ booleanisDone() Returns true if this task completed.
ˆ booleancancel(booleanmayInterruptIfRunning)
Attempts to cancel execution of this task.
ˆ booleanisCancelled()
Returns true if this task was canceled before it completed
normally.
The ExecutorService adds life-cycle support to shut down the execu-
tor framework and is compatible with the Executor interface. Developers
 
Search WWH ::




Custom Search