Class TaskExecutorPartitionHandler
java.lang.Object
org.springframework.batch.core.partition.support.AbstractPartitionHandler
org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler
- All Implemented Interfaces:
PartitionHandler
,StepHolder
,org.springframework.beans.factory.InitializingBean
public class TaskExecutorPartitionHandler
extends AbstractPartitionHandler
implements StepHolder, org.springframework.beans.factory.InitializingBean
A
By default, the thread pool is synchronous.
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.
By default, the thread pool is synchronous.
- Since:
- 2.0
- Author:
- Sebastien Gerard, Dave Syer, Mahmoud Ben Hassine
-
Field Summary
Fields inherited from class org.springframework.batch.core.partition.support.AbstractPartitionHandler
gridSize
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected FutureTask<StepExecution>
createTask
(Step step, StepExecution stepExecution) Creates the task executing the given step in the context of the given execution.protected Set<StepExecution>
doHandle
(StepExecution managerStepExecution, Set<StepExecution> partitionStepExecutions) Executes the specifiedStepExecution
instances and returns an updated view of them.getStep()
The step instance that will be executed in parallel by this handler.void
Setter for theStep
that will be used to execute the partitionedStepExecution
.void
setTaskExecutor
(org.springframework.core.task.TaskExecutor taskExecutor) Setter for theTaskExecutor
that is used to farm out step executions to multiple threads.Methods inherited from class org.springframework.batch.core.partition.support.AbstractPartitionHandler
getGridSize, handle, setGridSize
-
Constructor Details
-
TaskExecutorPartitionHandler
public TaskExecutorPartitionHandler()
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
setTaskExecutor
public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor) Setter for theTaskExecutor
that is used to farm out step executions to multiple threads.- Parameters:
taskExecutor
- aTaskExecutor
-
setStep
Setter for theStep
that will be used to execute the partitionedStepExecution
. This is a regular Spring Batch step, with all the business logic required to complete an execution based on the input parameters in itsStepExecution
context.- Parameters:
step
- theStep
instance to use to execute business logic
-
getStep
The step instance that will be executed in parallel by this handler.- Specified by:
getStep
in interfaceStepHolder
- Returns:
- the step instance that will be used
- See Also:
-
doHandle
protected Set<StepExecution> doHandle(StepExecution managerStepExecution, Set<StepExecution> partitionStepExecutions) throws Exception Description copied from class:AbstractPartitionHandler
Executes the specifiedStepExecution
instances and returns an updated view of them. Throws anException
if anything goes wrong.- Specified by:
doHandle
in classAbstractPartitionHandler
- Parameters:
managerStepExecution
- the whole partition executionpartitionStepExecutions
- theStepExecution
instances to execute- Returns:
- an updated view of these completed
StepExecution
instances - Throws:
Exception
- 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.
-
createTask
Creates the task executing the given step in the context of the given execution.- Parameters:
step
- the step to executestepExecution
- the given execution- Returns:
- the task executing the given step
-