public final class BatchingExecutor<P extends BatchedWorkProcessor> extends Object
Useful when works can be merged together for optimization purposes (bulking in Elasticsearch), or when they should never be executed in parallel (writes to a Lucene index).
| Constructor and Description |
|---|
BatchingExecutor(String name,
P processor,
int maxTasksPerBatch,
boolean fair,
FailureHandler failureHandler) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<?> |
getCompletion() |
void |
start(ExecutorService executorService)
Start the executor, allowing works to be submitted
through
submit(BatchedWork). |
void |
stop()
Stop the executor, no longer allowing works to be submitted
through
submit(BatchedWork). |
void |
submit(BatchedWork<? super P> work)
Submit a work for execution.
|
String |
toString() |
public BatchingExecutor(String name, P processor, int maxTasksPerBatch, boolean fair, FailureHandler failureHandler)
name - The name of the executor thread (and of this executor when reporting errors)processor - A task processor. May not be thread-safe.maxTasksPerBatch - The maximum number of tasks to process in a single batch.
Higher values mean more opportunity for the processor to optimize execution, but higher heap consumption.fair - if true tasks are always submitted to the
processor in FIFO order, if false tasks submitted
when the internal queue is full may be submitted out of order.failureHandler - A failure handler to report failures of the background thread.public void start(ExecutorService executorService)
submit(BatchedWork).executorService - An executor service with at least one thread.public void stop()
submit(BatchedWork).
This will remove pending works from the queue.
public void submit(BatchedWork<? super P> work) throws InterruptedException
Must not be called when the executor is stopped.
work - A work to execute.InterruptedException - If the current thread is interrupted while enqueuing the work.public CompletableFuture<?> getCompletion()
Copyright © 2006-2020 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.