Name: _____________________________ 6 Digit StudentID: ___ ___ ___ ___ ___ ___

Worksheet 26: Executor Service

Interface Future<V>

V get()
Waits if necessary for the computation to complete, and then retrieves its result.

Interface ExecutorService

<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
Executes the given tasks, returning a list of Futures holding their status and results when all complete. Future.isDone() is true for each element of the returned list. 
<T> Future<T> submit(Callable<T> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's get method will return the task's result upon successful completion.

If you would like to immediately block waiting for a task, you can use constructions of the form result = exec.submit(aCallable).get();

Using executor.submit(task) and future.get(), write pseudocode for doItYourselfInvokeAll() which meets the spec of invokeAll():

<T> List<Future<T>> doItYourselfInvokeAll(ExecutorService executor, Collection<? extends Callable<T>> tasks) {











Post Lecture

Synthesize today's class session

 

 

What is unclear?