The entrance to executing a JSR-352 based job is through the
javax.batch.operations.JobOperator. Spring Batch provides our own implementation to
this interface (org.springframework.batch.core.jsr.launch.JsrJobOperator). This
implementation is loaded via the javax.batch.runtime.BatchRuntime. Launching a
JSR-352 based batch job is implemented as follows:
JobOperator jobOperator = BatchRuntime.getJobOperator();
long jobExecutionId = jobOperator.start("fooJob", new Properties());
The above code does the following:
Bootstraps a base ApplicationContext - In order to provide batch functionality, the framework
needs some infrastructure bootstrapped. This occurs once per JVM. The components that are
bootstrapped are similar to those provided by @EnableBatchProcessing.
Specific details can be found in the javadoc for the JsrJobOperator.
Loads an ApplicationContext for the job requested - In the example
above, the framework will look in /META-INF/batch-jobs for a file named fooJob.xml and load a
context that is a child of the shared context mentioned previously.
Launch the job - The job defined within the context will be executed asynchronously. The
JobExecution's id will be returned.
![]() | Note |
|---|---|
All JSR-352 based batch jobs are executed asynchronously. |
When JobOperator#start is called using SimpleJobOperator,
Spring Batch determines if the call is an initial run or a retry of a previously executed run. Using the
JSR-352 based JobOpeator#start(String jobXMLName, Properties jobParameters), the
framework will always create a new JobInstance (JSR-352 job parameters are
non-identifying). In order to restart a job, a call to
JobOperator#restart(long executionId, Properties restartParameters) is required.