org.springframework.batch.core.partition.support

## 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 `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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TaskExecutorPartitionHandler()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()`
    `protected java.util.concurrent.FutureTask<StepExecution>` | `createTask(Step step, StepExecution stepExecution)` Creates the task executing the given step in the context of the given execution.
    `protected java.util.Set<StepExecution>` | `doHandle(StepExecution managerStepExecution, java.util.Set<StepExecution> partitionStepExecutions)` Executes the specified `StepExecution` instances and returns an updated view of them.
    `Step` | `getStep()` The step instance that will be executed in parallel by this handler.
    `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.

    - ### Methods inherited from class org.springframework.batch.core.partition.support.AbstractPartitionHandler

      `getGridSize, handle, setGridSize`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TaskExecutorPartitionHandler

          public TaskExecutorPartitionHandler()

  - ### Method Detail

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`

    - #### setTaskExecutor

          public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)

      Setter for the `TaskExecutor` that is used to farm out step executions to multiple threads.
      Parameters:
        `taskExecutor` - a `TaskExecutor`

    - #### setStep

          public void setStep(Step step)

      Setter for the `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.
      Parameters:
        `step` - the `Step` instance to use to execute business logic

    - #### getStep

          public Step getStep()

      The step instance that will be executed in parallel by this handler.
      Specified by:
        `getStep` in interface `StepHolder`
      Returns:
        the step instance that will be used
      See Also:
        `StepHolder.getStep()`

    - #### doHandle

          protected java.util.Set<StepExecution> doHandle(StepExecution managerStepExecution,
                                                          java.util.Set<StepExecution> partitionStepExecutions)
                                                   throws java.lang.Exception

      Description copied from class: `AbstractPartitionHandler`
      Executes the specified `StepExecution` instances and returns an updated view of them. Throws an `Exception` if anything goes wrong.
      Specified by:
        `doHandle` in class `AbstractPartitionHandler`
      Parameters:
        `managerStepExecution` - the whole partition execution
        `partitionStepExecutions` - the `StepExecution` instances to execute
      Returns:
        an updated view of these completed `StepExecution` instances
      Throws:
        `java.lang.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

          protected java.util.concurrent.FutureTask<StepExecution> createTask(Step step,
                                                                              StepExecution stepExecution)

      Creates the task executing the given step in the context of the given execution.
      Parameters:
        `step` - the step to execute
        `stepExecution` - the given execution
      Returns:
        the task executing the given step