public class TaskExecutorPartitionHandler extends Object implements PartitionHandler, StepHolder, org.springframework.beans.factory.InitializingBean
PartitionHandler
that uses a TaskExecutor
to execute the
partitioned Step
locally in multiple threads. This can be an
effective approach for scaling batch steps that are IO intensive, like
directory and filesystem scanning and copying.Constructor and Description |
---|
TaskExecutorPartitionHandler() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
Step |
getStep()
The step instance that will be executed in parallel by this handler.
|
Collection<StepExecution> |
handle(StepExecutionSplitter stepExecutionSplitter,
StepExecution masterStepExecution)
Main entry point for
PartitionHandler interface. |
void |
setGridSize(int gridSize)
Passed to the
StepExecutionSplitter in the
handle(StepExecutionSplitter, StepExecution) method, instructing
it how many StepExecution instances are required, ideally. |
void |
setStep(Step step)
Setter for the
Step that will be used to execute the partitioned
StepExecution . |
void |
setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
Setter for the
TaskExecutor that is used to farm out step
executions to multiple threads. |
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public void setGridSize(int gridSize)
StepExecutionSplitter
in the
handle(StepExecutionSplitter, StepExecution)
method, instructing
it how many StepExecution
instances are required, ideally. The
StepExecutionSplitter
is allowed to ignore the grid size in the
case of a restart, since the input data partitions must be preserved.gridSize
- the number of step executions that will be createdpublic void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
TaskExecutor
that is used to farm out step
executions to multiple threads.taskExecutor
- a TaskExecutor
public void setStep(Step step)
Step
that will be used to execute the partitioned
StepExecution
. This is a regular Spring Batch step, with all the
business logic required to complete an execution based on the input
parameters in its StepExecution
context.step
- the Step
instance to use to execute business logicpublic Step getStep()
getStep
in interface StepHolder
StepHolder.getStep()
public Collection<StepExecution> handle(StepExecutionSplitter stepExecutionSplitter, StepExecution masterStepExecution) throws Exception
PartitionHandler
PartitionHandler
interface. The splitter
creates all the executions that need to be farmed out, along with their
input parameters (in the form of their ExecutionContext
). The
master step execution is used to identify the partition and group
together the results logically.handle
in interface PartitionHandler
stepExecutionSplitter
- a strategy for generating a collection of
StepExecution
instancesmasterStepExecution
- the master step execution for the whole partitionStepExecution
instancesException
- if anything goes wrong. This allows implementations to
be liberal and rely on the caller to translate an exception into a step
failure as necessary.PartitionHandler.handle(StepExecutionSplitter, StepExecution)
Copyright © 2013 SpringSource. All rights reserved.