Class Distribute
-
Method Summary
Modifier and TypeMethodDescriptionstatic <C> voidplans(TaskExecutor taskExecutor, C context, Runnable onCompletion, List<Plan<C>> plans) Distribute the given list of plans across the threads of the task executor.static <C,T> void slices(TaskExecutor taskExecutor, C context, Runnable onCompletion, List<T> list, BiConsumer<List<T>, C> action) Distribute the given list of tasks in chunks across the threads of the task executor.static intsliceSize(TaskExecutor taskExecutor, int totalSize) static intsliceSize(TaskExecutor taskExecutor, int totalSize, int denominator) static <C,T> void tasks(TaskExecutor taskExecutor, C context, Runnable onCompletion, List<T> list, BiConsumer<T, C> action) Distribute the given list of tasks across the threads of the task executor.
-
Method Details
-
tasks
public static <C,T> void tasks(TaskExecutor taskExecutor, C context, Runnable onCompletion, List<T> list, BiConsumer<T, C> action) Distribute the given list of tasks across the threads of the task executor.An effort is made to balance the load across threads while also ensuring each runnable passed to the executor is large enough to amortize the cost of scheduling it.
- Type Parameters:
C- The context type.T- The object type.- Parameters:
taskExecutor- The task executor to run on.context- The context to pass to each task.onCompletion- The action to run when all tasks are complete.list- The list of objects to run tasks on.action- The action to run on each object.
-
slices
public static <C,T> void slices(TaskExecutor taskExecutor, C context, Runnable onCompletion, List<T> list, BiConsumer<List<T>, C> action) Distribute the given list of tasks in chunks across the threads of the task executor.Unlike
tasks(TaskExecutor, Object, Runnable, List, BiConsumer), this method gives the action a list of objects to work on, rather than a single object. This may be handy for when you can share some thread local objects between individual elements of the list.An effort is made to balance the load across threads while also ensuring each runnable passed to the executor is large enough to amortize the cost of scheduling it.
- Type Parameters:
C- The context type.T- The object type.- Parameters:
taskExecutor- The task executor to run on.context- The context to pass to each task.onCompletion- The action to run when all tasks are complete.list- The list of objects to run tasks on.action- The action to run on each slice.
-
plans
public static <C> void plans(TaskExecutor taskExecutor, C context, Runnable onCompletion, List<Plan<C>> plans) Distribute the given list of plans across the threads of the task executor.Plan scheduling is normally lightweight compared to the cost of execution, but when many hundreds or thousands of plans need to be scheduled it may be beneficial to parallelize. This method does exactly that, distributing larger chunks of plans to be scheduled in batches.
An effort is made to balance the load across threads while also ensuring each runnable passed to the executor is large enough to amortize the cost of scheduling it.
- Type Parameters:
C- The context type.- Parameters:
taskExecutor- The task executor to run on.context- The context to pass to the plans.onCompletion- The action to run when all plans are complete.plans- The list of plans to execute.
-
sliceSize
-
sliceSize
-