FULL PRODUCT VERSION : Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64) A DESCRIPTION OF THE PROBLEM : The typed method signature for the invokeAll() call in ExecutorService is incorrect. It should be declared: <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>>��tasks) I have included a tiny test program which shows the compilation error that occurs because of the method declaration. The method is declared to take a collection of exactly the type Callable, which is improper. As the implementation of the invokeAll() does not need to add to the collection it is almost certainly not needed, but requires developers to reassign objects to expose the proper type when not building a new collection. a better declaration would be: <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>>��tasks) This change makes the class much more flexible, and the change should be made to the other similar methods in the class: <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>>��tasks, long��timeout, TimeUnit��unit) <T> T invokeAny(Collection<? extends Callable<T>>��tasks) <T> T invokeAny(Collection<? extends Callable<T>>��tasks, long��timeout, TimeUnit��unit) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.util.*; import java.util.concurrent.*; public class Test implements Callable<Object> { public static void main(String[] args) { ExecutorService service = Executors.newSingleThreadExecutor(); Test test = new Test(); // This does not work because of the invokeAll() declaration. service.invokeAll(Collections.singleton(test)); // This does but the assignment should not be necessary. Callable<Object> callable = test; service.invokeAll(Collections.singleton(callable)); } public Object call() throws Exception { System.out.println("Called."); } } ---------- END SOURCE ---------- ###@###.### 2005-05-10 09:38:27 GMT
|