private void mapJournalsAndReportErrorsParallel ( JournalClosure closure , String status ) throws IOException { // set-up calls List < Future < JournalAndStream >> jasResponeses = new ArrayList < Future < JournalAndStream > > ( journals . size ( ) ) ; for ( JournalAndStream jas : journals ) { jasResponeses . add ( executor . submit ( new JournalSetWorker ( jas , closure , status ) ) ) ; } List < JournalAndStream > badJAS = null ; // iterate through responses for ( Future < JournalAndStream > future : jasResponeses ) { JournalAndStream jas = null ; try { jas = future . get ( ) ; } catch ( ExecutionException e ) { throw new IOException ( "This should never happen!!!" , e ) ; } catch ( InterruptedException e ) { throw new IOException ( "Interrupted whe performing journal operations" , e ) ; } if ( jas == null ) continue ; // the worker returns the journal if the operation failed if ( badJAS == null ) badJAS = new LinkedList < JournalAndStream > ( ) ; badJAS . add ( jas ) ; } disableAndReportErrorOnJournals ( badJAS , status ) ; }
Apply the given operation across all of the journal managers disabling any for which the closure throws an IOException . Do it in parallel .