Class TaskExecutor.TaskGroup<T>

  • Type Parameters:
    T - the return type of all the callables
    Enclosing class:
    TaskExecutor

    private static final class TaskExecutor.TaskGroup<T>
    extends java.lang.Object
    Holds all the sub-tasks that a certain operation gets split into as it gets parallelized and exposes the ability to invoke such tasks and wait for them all to complete their execution and provide their results. Ensures that each task does not get parallelized further: this is important to avoid a deadlock in situations where one executor thread waits on other executor threads to complete before it can progress. This happens in situations where for instance Query.createWeight(IndexSearcher, ScoreMode, float) is called as part of searching each slice, like TopFieldCollector.populateScores(ScoreDoc[], IndexSearcher, Query) does. Additionally, if one task throws an exception, all other tasks from the same group are cancelled, to avoid needless computation as their results would not be exposed anyways. Creates one FutureTask for each Callable provided
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Collection<java.util.concurrent.RunnableFuture<T>> futures  
    • Constructor Summary

      Constructors 
      Constructor Description
      TaskGroup​(java.util.Collection<java.util.concurrent.Callable<T>> callables)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean assertAllFuturesCompleted()  
      private void cancelAll()  
      (package private) java.util.concurrent.RunnableFuture<T> createTask​(java.util.concurrent.Callable<T> callable)  
      (package private) java.util.List<T> invokeAll​(java.util.concurrent.Executor executor)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • futures

        private final java.util.Collection<java.util.concurrent.RunnableFuture<T>> futures
    • Constructor Detail

      • TaskGroup

        TaskGroup​(java.util.Collection<java.util.concurrent.Callable<T>> callables)
    • Method Detail

      • createTask

        java.util.concurrent.RunnableFuture<T> createTask​(java.util.concurrent.Callable<T> callable)
      • invokeAll

        java.util.List<T> invokeAll​(java.util.concurrent.Executor executor)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • assertAllFuturesCompleted

        private boolean assertAllFuturesCompleted()
      • cancelAll

        private void cancelAll()