final int queueSize = workList.size();
final ExecutorService executor = resources.getWorkersExecutor();
final Future<LuceneWork>[] submittedTasks = new Future[ queueSize ];
for ( int i = 0; i < queueSize; i++ ) {
LuceneWork luceneWork = workList.get( i );
SingleTaskRunnable task = new SingleTaskRunnable( luceneWork, resources, indexWriter, monitor );
submittedTasks[i] = executor.submit( task, luceneWork );
}
boolean allTasksSuccessful = true;
// now wait for all tasks being completed before releasing our lock
// (this thread waits even in async backend mode)
for ( int i = 0; i < queueSize; i++ ) {
Future<LuceneWork> task = submittedTasks[i];
try {
LuceneWork work = task.get();
errorContextBuilder.workCompleted( work );
}
catch (ExecutionException e) {
errorContextBuilder.addWorkThatFailed( workList.get( i ) );
errorContextBuilder.errorThatOccurred( e.getCause() );