Java Reference
In-Depth Information
<beans:property name="keys" value="job.stockFile,job.customerFile"/>
<job id="subJobJob">
<step id="step0" next="step4 ">
<job ref="preProcessingJob"
job-parameters-extractor="jobParametersExtractor "/>
<step id="step4" parent="runBatch"/>
You might be wondering about the jobParametersExtractor bean in Listing 4-48. When you launch
a job, it's identified by the job name and the job parameters. In this case, you aren't passing the
parameters to your sub job, preProcessingJob , by hand. Instead, you define a class to extract the
parameters from either the JobParameters of the parent job or the ExecutionContext (the
DefaultJobParameterExtractor checks both places) and pass those parameters to the child job. Your
extractor pulls the values from the job.stockFile and job.customerFile job parameters and passes
those as parameters to preProcessingJob .
When preProcessingJob executes, it's identified in the JobRepository just like any other job. It has
its own job instance, execution context, and related database records.
A word of caution about using the job-step approach: this may seem like a good way to handle job
dependencies. Creating individual jobs and being able to then string them together with a master job is a
powerful feature. However, this can severely limit the control of the process as it executes. It isn't
uncommon in the real world to need to pause a batch cycle or skip jobs based on external factors
(another department can't get you a file in time to have the process finished in the required window, and
so on). However, the ability to manage jobs exists at a single job level. Managing entire trees of jobs that
could be created using this functionality is problematic and should be avoided. Linking jobs together in
this manner and executing them as one master job severely limits the capability to handle these types of
situations and should also be avoided.
The last piece of the flow puzzle is the ability Spring Batch provides to execute multiple flows in
parallel, which is covered next.
Parallelization of Flows
Although you learn about parallelization later in this topic, this section covers the Spring Batch
functionality to execute step flows in parallel. One of the strengths of using Java for batch processing and
the tools that Spring Batch provides is the ability to bring multithreaded processing to the batch world in
a standardized way. One of the easiest ways to execute steps in parallel is to split them in your job.
The split flow is a step that allows you to list flows that you want to execute in parallel. Each flow is
started at the same time, and the step isn't considered complete until all the flows within it have
completed. If any one of the flows fails, the split flow is considered to have failed. To see how the split
step works, look at Listing 4-49.
Listing 4-49. Parallel Flows Using a Split Step
<job id="flowJob">
<split id="preprocessingStep" next="batchStep">
<step id="step1" parent="loadStockFile" next="step2"/>
<step id="step2" parent="loadCustomerFile"/>
Search WWH ::

Custom Search