Batch Processing in Java EE
This section lists the components of the batch processing framework in Java EE and provides an overview of the steps you have to follow to create a batch application.
The following topics are addressed here:
The Batch Processing Framework
Java EE includes a batch processing framework that consists of the following elements:
Batch applications in Java EE contain XML files and Java classes. The XML files define the structure of a job in terms of batch artifacts and the relationships between them. (A batch artifact is a part of a chunk-oriented step, a task-oriented step, a decision element, or another component of a batch application). The Java classes implement the application logic of the batch artifacts defined in the XML files. The batch runtime parses the XML files and loads the batch artifacts as Java classes to run the jobs in a batch application.
Creating Batch Applications
The process for creating a batch application in Java EE is the following.
The following sections describe in detail how to use the components of the batch processing framework in Java EE to create batch applications.
Elements of a Batch Job
A batch job can contain one or more of the following elements:
Steps are described in Introduction to Batch Processing, and can be chunk-oriented or task-oriented. Chunk-oriented steps can be partitioned steps. In a partitioned chunk step, the processing of one item does not depend on other items, so these steps can run in more than one thread.
A flow is a sequence of steps that execute as a unit. A sequence of related steps can be grouped together into a flow. The steps in a flow cannot transition to steps outside the flow. The flow transitions to the next element when its last step completes.
A split is a set of flows that execute in parallel; each flow runs on a separate thread. The split transitions to the next element when all its flows complete.
Decision elements use the exit status of the previous step to determine the next step or to terminate the batch job.
Properties and Parameters
Jobs and steps can have a number of properties associated with them. You define properties in the job definition file, and batch artifacts access these properties using context objects from the batch runtime. Using properties in this manner enables you to decouple static parameters of the job from the business logic and to reuse batch artifacts in different job definition files.
Java EE applications can also pass parameters to a job when they submit it to the batch runtime. This enables you to specify dynamic parameters that are only known at runtime. Parameters are also necessary for partitioned steps, since each partition needs to know, for example, what range of items to process.
Job Instances and Job Executions
A job definition can have multiple instances, each with different parameters. A job execution is an attempt to run a job instance. The batch runtime maintains information about job instances and job executions, as described in Checking the Status of a Job.
Batch and Exit Status
The state of jobs, steps, splits, and flows is represented in the batch runtime as a batch status value. Batch status values are listed Table 58-1. They are represented as strings.
Table 58-1 Batch Status Values
Java EE applications can submit jobs and access the batch status of a
job using the
For flows, the batch status is that of its last step. For splits, the batch status is the following:
The batch status for jobs, steps, splits, and flows is set by the batch runtime. Jobs, steps, splits, and flows also have an exit status, which is a user-defined value based on the batch status. You can set the exit status inside batch artifacts or in the job definition file. You can access the exit status in the same manner as the batch status, described above. The default value for the exit status is the same as the batch status.