Overview
Synchronous job is explained. Synchronous job is the execution method of launching a new process through shell by job scheduler and returning the execution result of the job to the caller.
The usage method of this function is same in the chunk model as well as tasklet model.
How to use
How to run a job by CommandLineJobRunner
is explained.
Refer to Create project for building and executing the application. Refer to Job parameters for how to specify and use job parameters. Some of the explanation in this section overlaps however, the elements of synchronous job are mainly explained.
How to run
In TERASOLUNA Batch 5.x, run the synchronous job using CommandLineJobRunner
provided by Spring Batch.
Start CommandLineJobRunner
by issuing java command as shown below.
$ java org.springframework.batch.core.launch.support.CommandLineJobRunner <jobPath> <options> <jobIdentifier> <jobParameters>
Items to be specified | Explanation | Required |
---|---|---|
jobPath |
Bean definition file path where the settings of the job to be run are described. Specify by relative path from classpath. |
|
options |
Specify various options (stop, restart etc.) at the time of launching. |
|
jobIdentifier |
As the identifier of the job, specify the job name in the bean definition or the job execution ID after executing the job. Normally, specify job name. Job execution ID is specified only when stopping or restarting. |
|
jobParameters |
Specify job arguments. Specify in |
The execution example when only the required items are specified, is shown below.
C:\xxx>java -cp "target\[artifactId]-[version].jar;lib\*" ^ # (1)
org.springframework.batch.core.launch.support.CommandLineJobRunner ^ # (2)
META-INF/jobs/job01.xml job01 # (3)
$ java -cp 'target/[artifactId]-[version].jar:lib/*' \ # (1) org.springframework.batch.core.launch.support.CommandLineJobRunner \ # (2) META-INF/jobs/job01.xml job01 # (3)
<batch:job id="job01" job-repository="jobRepository"> <!-- (3) -->
<batch:step id="job01.step01">
<batch:tasklet transaction-manager="jobTransactionManager">
<batch:chunk reader="employeeReader"
processor="employeeProcessor"
writer="employeeWriter" commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>
Sr. No. | Explanation |
---|---|
(1) |
Specify the batch application jar and dependent jar in |
(2) |
Specify |
(3) |
Pass the run arguments along the |
Execution example when launch parameters are specified as the optional items, is shown below.
C:\xxx>java -cp "target\[artifactId]-[version].jar;lib\*" ^
org.springframework.batch.core.launch.support.CommandLineJobRunner ^
META-INF/jobs/setupJob.xml setupJob target=server1 outputFile=/tmp/result.csv # (1)
.Execution example of CommandLineJobRunner in Bash
$ java -cp 'target/[artifactId]-[version].jar:lib/*' \ org.springframework.batch.core.launch.support.CommandLineJobRunner \ META-INF/jobs/setupJob.xml setupJob target=server1 outputFile=/tmp/result.csv # (1)
Sr. No. | Explanation |
---|---|
(1) |
|
Options
Supplement the options indicated in CommandLineJobRunner syntax.
In CommandLineJobRunner
, the following 4 launch options can be used.
Here, only the overview of each option is explained.
- -restart
-
Restarts the failed job. Refer to Reprocessing for the details.
- -stop
-
Stops a running job. Refer to Job management for the details.
- -abandon
-
Abandons a stopped job. The abandoned job cannot be restarted. In TERASOLUNA Batch 5.x, there is no case of using this option, hence it is not explained.
- -next
-
Runs the job executed once in the past, again. However, in TERASOLUNA Batch 5.x, this option is not used.
In TERASOLUNA Batch 5.x, it is for avoiding the restriction "Running the job by the same parameter is recognized as the same job and the same job can be executed only once" that is given by default in Spring Batch.
The details are explained in regarding parameter conversion class.
For using this option, implementation class ofJobParametersIncrementer
interface is required, it is not set inTERASOLUNA Batch 5.x.
Therefore, when this option is specified and launched, an error occurs because the required Bean definition does not exist.