TERASOLUNA Batch Framework for Java (5.x) Development Guideline - version 5.1.1.RELEASE, 2018-3-16
> INDEX

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.

overview of sync job
Overview of synchronous job
sequence of sync job
Sequence of synchronous job

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.

CommandLineJobRunner syntax
$ java org.springframework.batch.core.launch.support.CommandLineJobRunner <jobPath> <options> <jobIdentifier> <jobParameters>
Items to be specified by the arguments
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 key=value format.

The execution example when only the required items are specified, is shown below.

Execution example of CommandLineJobRunner in command prompt
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)
Execution example of CommandLineJobRunner in Bash
$ java -cp 'target/[artifactId]-[version].jar:lib/*' \ # (1)
    org.springframework.batch.core.launch.support.CommandLineJobRunner \ # (2)
    META-INF/jobs/job01.xml job01 # (3)
Settings of Bean definition(Abstract)
<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>
Items list of setting contents
Sr. No. Explanation

(1)

Specify the batch application jar and dependent jar in classpath at the time of executing java command. Here, it is specified by command arguments however, environment variables can also be used.

(2)

Specify CommandLineJobRunner with FQCN in the class to be run.

(3)

Pass the run arguments along the CommandLineJobRunner. Here, 2 job names are specified as jobPath and jobIdentifier.

Execution example when launch parameters are specified as the optional items, is shown below.

Execution example of CommandLineJobRunner in command prompt
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)
Items list of setting contents
Sr. No. Explanation

(1)

target=server1 and outputFile=/tmp/result.csv are specified as job running parameters.

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 of JobParametersIncrementer 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.

TERASOLUNA Batch Framework for Java (5.x) Development Guideline - version 5.1.1.RELEASE, 2018-3-16