Java Concurrency: How can I tell which Future belongs to which Callable during processing?

callable, concurrency, executorservice, future, java

Solution

Based on Java reference, `invokeAll(uniqueCallables)` preserves the order in `List<Future>` as the order produced by `uniqueCallables.iterator()`:

Returns: A list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed.

Problem

I have a collection of Callables and a ExecutorService. When I invokeAll, I get back a list of Future objects. How can I tell which Future object mapped to which Callable before the Future completes? I can tell afterwards because the Code: ``` ExecutorService es = .....; Collection<Callables> uniqueCallables = .....; // each Callable is unique! List<Future> futures = es.invokeAll(uniqueCallables); // TODO--find unique Future A which is the future for Callable A! ```

Original source