ExecutorService.invokeAll does NOT support collection of runnable task

rai.skumar picture rai.skumar · Jun 6, 2014 · Viewed 9.8k times · Source

Wanted to run collection of Runnable task through invokeAll(..) method of ExecutorService. But that's not supported as of now (supports collection of Callable task only)

Any specific reason for this? What's the alternative to do something similar.

Answer

rai.skumar picture rai.skumar · Jun 18, 2014
Runnable task = new Runnable() { 
     public void run() {

     }
};

Callable<Object> c = Executors.callable(task);

Just found that, Executors provides utility method to convert Runnable task into a Callable task. That explains why we don't have overloaded invokeAll which takes Runnable task as well.