- java.lang.Object
-
- org.apache.lucene.search.TaskExecutor
-
public final class TaskExecutor extends java.lang.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 singleinvokeAll(Collection)
method that takes a collection ofCallable
s 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-levelinvokeAll(Collection)
calls, and not for potentialinvokeAll(Collection)
calls made from one of the tasks. This is to prevent deadlock with certain types of pool based executors (e.g.ThreadPoolExecutor
).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TaskExecutor.TaskGroup<T>
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.
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.Executor
executor
private static java.lang.ThreadLocal<java.lang.Integer>
numberOfRunningTasksInCurrentThread
-
Constructor Summary
Constructors Constructor Description TaskExecutor(java.util.concurrent.Executor executor)
Creates a TaskExecutor instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> java.util.List<T>
invokeAll(java.util.Collection<java.util.concurrent.Callable<T>> callables)
Execute all the callables provided as an argument, wait for them to complete and return the obtained results.java.lang.String
toString()
-
-
-
Method Detail
-
invokeAll
public <T> java.util.List<T> invokeAll(java.util.Collection<java.util.concurrent.Callable<T>> callables) throws java.io.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:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-