Class TaskExecutor

java.lang.Object
org.apache.lucene.search.TaskExecutor

public final class TaskExecutor extends Object
Executor wrapper responsible for the execution of concurrent tasks. Used to parallelize search across segments as well as query rewrite in some cases. Exposes a single invokeAll(Collection) method that takes a collection of Callables and executes them concurrently/ Once all tasks are submitted to the executor, it blocks and wait for all tasks to be completed, and then returns a list with the obtained results. Ensures that the underlying executor is only used for top-level invokeAll(Collection) calls, and not for potential invokeAll(Collection) calls made from one of the tasks. This is to prevent deadlock with certain types of pool based executors (e.g. ThreadPoolExecutor).
WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Constructor Details

    • TaskExecutor

      public TaskExecutor(Executor executor)
      Creates a TaskExecutor instance
      Parameters:
      executor - the executor to be used for running tasks concurrently
  • Method Details

    • invokeAll

      public <T> List<T> invokeAll(Collection<Callable<T>> callables) throws IOException
      Execute all the callables provided as an argument, wait for them to complete and return the obtained results. If an exception is thrown by more than one callable, the subsequent ones will be added as suppressed exceptions to the first one that was caught.
      Type Parameters:
      T - the return type of the task execution
      Parameters:
      callables - the callables to execute
      Returns:
      a list containing the results from the tasks execution
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object