public < T > Collection < T > startWorking ( Callable < T > [ ] callables ) { List < Future < T >> list = new ArrayList < Future < T > > ( ) ; for ( int i = 0 ; i < callables . length ; i ++ ) { list . add ( executor . submit ( callables [ i ] ) ) ; } ArrayList < T > resultList = new ArrayList < T > ( callables . length ) ; // Now retrieve the result T output ; for ( Future < T > future : list ) { try { output = future . get ( ) ; if ( output != null ) resultList . add ( output ) ; } catch ( InterruptedException e ) { throw new SystemException ( e ) ; } catch ( ExecutionException e ) { throw new SystemException ( e ) ; } } return resultList ; }
Start the array of the callables