Java Reference
In-Depth Information
A parameter incrementer: Increments job parameters with each JobExecution
Listeners: Any job-level listeners
Job parameter validator: Validates that the parameters passed to a job meet any
requirements
All of these concepts are new and are discussed later in this chapter. For now, all you need to be
aware of is that when these values are set on an abstract job, any job extending the parent job inherits
them. Things the child doesn't inherit include step configurations, step flows, and decisions. These must
be defined in any job using them.
Inheritance can be helpful not only to consolidate the configuration of common attributes but also
to standardize how certain things are done. Because the last example began looking at parameters and
their validation, that seems like a logical next topic.
Job Parameters
You've read a few times that a JobInstance is identified by the job name and the parameters passed into
the job. You also know that because of that, you can't run the same job more than once with the same
parameters. If you do, you receive an
org.springframework.batch.core.launch.JobInstanceAlreadyCompleteException telling you that if you'd
like to run the job again, you need to change the parameters (as shown in Listing 4-5).
Listing 4-5. What Happens When You Try to Run a Job Twice with the Same Parameters
2010-11-28 21:06:03,598 ERROR
org.springframework.batch.core.launch.support.CommandLineJobRunner.main()
[org.springframework.batch.core.launch.support.CommandLineJobRunner] - <Job Terminated in
error: A job instance already exists and is complete for parameters={}. If you want to run
this job again, change the parameters.>
org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance
already exists and is complete for parameters={}. If you want to run this job again, change
the parameters.
at
org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(Simpl
eJobRepository.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
So how do you pass parameters to your jobs? Spring Batch allows you not only to pass parameters to
your jobs but also to automatically increment them 5 or validate them before your job runs. You start by
looking at how to pass parameters to your jobs.
Passing parameters to your job depends on how you're calling your job. One of the functions of the
job runner is to create an instance of org.springframework.batch.core.JobParameters and pass it to the
JobLauncher for execution. This makes sense because the way you pass parameters is different if you
5 It may make sense to have a parameter that is incremented for each JobInstance . For example, if the
date the job is run is one of its parameters, this can be addressed automatically via a parameter
incrementer.
 
Search WWH ::




Custom Search