Read more : http://www.ehow.com/how_8498918_remove-title-blogger-pages.html

Thursday, 1 May 2014

Parallel Step Example

Hi,

Spring batch provides so many features for java batch processing , parallel step process is one of the feature of spring batch frame work.

In the parallel step process we can execute / process independent steps at a time, this will reduce Process time of the job.

Parallel step process is a flavor of multi-threaded process provided by spring batch frame work

Please note this feature will be  used when there is no dependency exists between the steps of a job process.

Following examples explain you how to configure parallel step execution

In this example I am using two tasklets for two steps

1) Tasklet1 prints Hello From Tasklet1
2) Tasklet2  prints Hello from Tasklet2

Job Configuration is as follows:

<batch:job id="parallelStepProcessing">
 <batch:split id="parallelSplit"  task-executor="parallelExecutor">
 <batch:flow>
  <batch:step id="hiTaskelt1">
<batch:tasklet ref="helloTasklet1" />
</batch:step>
</batch:flow>
<batch:flow>
<batch:step id="hiTasklet2">
<batch:tasklet ref="haiTasklet2" />
</batch:step>
</batch:flow>
</batch:split>
</batch:job>
 <bean id="parallelExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>

<bean id="helloTasklet1" class="packagename.Tasklet1"/>

<bean id="haiTasklet2" class="packagename.Tasklet2"/>

Please note that a flow should have atleast one step

class Tasklet1 implements Tasklet{
@Override
public RepeatStatus execute(StepContribution stepContri, ChunkContext context) throws Exception{
                 System.out.println("Hello from tasklet1");
return RepeatStatus.FINISHED;

}
}

class Tasklet2 implements Tasklet{
@Override
public RepeatStatus execute(StepContribution stepContri, ChunkContext context) throws Exception{
                 System.out.println("Hello from tasklet2");
return RepeatStatus.FINISHED;

}
}

Please refer http://docs.spring.io/spring-batch/reference/html/scalability.html for more details
Hope this will help you in designing spring batch parallel step process.. 




No comments:

Post a Comment