Java Reference
In-Depth Information
Listing 11-13. Step 2 of ParallelJob
<beans:bean id="jmsReader" class="org.springframework.batch.item.jms.JmsItemReader">
<beans:property name="jmsTemplate" ref="jmsTemplate"/>
<beans:bean id="orderWriter"
<beans:property name="sessionFactory" ref="sessionFactory"/>
<step id="batchOrderProcessingStep">
<chunk reader="jmsReader" writer="orderWriter" commit-interval="10"/>
<job id="parallelJob">
<step id="step1" parent="preloadDataStep" next="step2"/>
<step id="step2" parent="batchOrderProcessingStep"/>
Next, you need to verify that the customer's credit card will go through and that you have the
inventory to fulfill the order. Because these functions aren't directly related, you can do them in parallel
to improve the overall throughput of the job. You'll look at how these steps are configured next.
Configuring the Parallel Steps
To execute steps in parallel, Spring Batch again uses Spring's TaskExecutor. In this case, each flow is
executed in its own thread, allowing you to execute multiple flows in parallel. To configure this, you use
Spring Batch's split tag. The split tag takes three required attributes:
id : The id of the element.
task-executor : A reference to the TaskExecutor implementation that Spring Batch
uses to manage the threading used for your parallel processing.
next : Tells Spring Batch what step to execute once all the flows complete
successfully. A split tag wraps multiple steps into a single pseudostep; if any of
the flows fails in its execution, the other steps running at the same time complete
and then the job fails when parallel processing was to end.
It's important to note that the execution order of a job using split is similar to that of a regular job.
In a regular job, a step doesn't complete until all the items are processed for the step and the next step
doesn't begin until the previous one is completed. Using split , the step after the split isn't executed
until all the flows configured within the split have been completed.
Search WWH ::

Custom Search