<h3id="_steps_in_batch_jobs">Steps in Batch Jobs</h3>
<divclass="paragraph">
<p>A step is an independent and sequential phase of a batch job. Batch jobs
contain chunk-oriented steps and task-oriented steps.</p>
</div>
<divclass="ulist">
<ul>
<li>
<p>Chunk-oriented steps (chunk steps) process data by reading items from
a data source, applying some business logic to each item, and storing
the results. Chunk steps read and process one item at a time and group
the results into a chunk. The results are stored when the chunk reaches
a configurable size. Chunk-oriented processing makes storing results
more efficient and facilitates transaction demarcation.</p>
<divclass="paragraph">
<p>Chunk steps have three parts.</p>
</div>
<divclass="ulist">
<ul>
<li>
<p>The input retrieval part reads one item at a time from a data source,
such as entries on a database, files in a directory, or entries in a log
file.</p>
</li>
<li>
<p>The business processing part manipulates one item at a time using the
business logic defined by the application. Examples include filtering,
formatting, and accessing data from the item for computing a result.</p>
</li>
<li>
<p>The output writing part stores a chunk of processed items at a time.</p>
<divclass="paragraph">
<p>Chunk steps are often long-running because they process large amounts of
data. Batch frameworks enable chunk steps to bookmark their progress
using checkpoints. A chunk step that is interrupted can be restarted
from the last checkpoint. The input retrieval and output writing parts
of a chunk step save their current position after the processing of each
chunk, and can recover it when the step is restarted.</p>
</div>
<divclass="paragraph">
<p><ahref="#BABFJBAH">Figure 58-1</a> shows the three parts of two steps in a
batch job.</p>
</div>
<divclass="paragraph">
<divclass="title"><strong>Figure 58-1 Chunk Steps in a Batch Job</strong></div>
<p><spanclass="image"><imgsrc="img/javaeett_dt_058.png" alt="This figure shows a batch job that contains two chunk steps: step A and step B. Step A has the three parts of a chunk-oriented step: input retrieval A, business processing A, and output writing A. Step B also has the three parts of a chunk-oriented step: input retrieval B, business processing B, and output writing B."></span></p>
</div>
</li>
</ul>
</div>
</li>
</ul>
</div>
<divclass="paragraph">
<p>For example, the phone billing application consists of two chunk steps.</p>
</div>
<divclass="ulist">
<ul>
<li>
<p>In the first step, the input retrieval part reads call records from
the registry; the business processing part associates each call with a
bill and creates a bill if one does not exist for an account; and the
output writing part stores each bill in a database.</p>
</li>
<li>
<p>In the second step, the input retrieval part reads bills from the
database; the business processing part calculates the tax and total
amount due for each bill; and the output writing part updates the
database records and generates printable versions of each bill.</p>
</li>
</ul>
</div>
<divclass="paragraph">
<p>This application could also contain a task step that cleaned up the
files from the bills generated for the previous month.</p>
<h3id="_status_and_decision_elements">Status and Decision Elements</h3>
<divclass="paragraph">
<p>Batch frameworks keep track of a status for every step in a job. The
status indicates if a step is running or if it has completed. If the
step has completed, the status indicates one of the following.</p>
</div>
<divclass="ulist">
<ul>
<li>
<p>The execution of the step was successful.</p>
</li>
<li>
<p>The step was interrupted.</p>
</li>
<li>
<p>An error occurred in the execution of the step.</p>
</li>
</ul>
</div>
<divclass="paragraph">
<p>In addition to steps, batch jobs can also contain decision elements.
Decision elements use the exit status of the previous step to determine
the next step or to terminate the batch job. Decision elements set the
status of the batch job when terminating it. Like a step, a batch job
can terminate successfully, be interrupted, or fail.</p>
</div>
<divclass="paragraph">
<p><ahref="#BCGDCDCA">Figure 58-2</a> shows an example of a job that contains
chunk steps, task steps and a decision element.</p>
</div>
<divid="BCGDCDCA" class="paragraph">
<divclass="title"><strong>Figure 58-2 Steps and Decision Elements in a Job</strong></div>
<p><spanclass="image"><imgsrc="img/javaeett_dt_059.png" alt="This figure shows a batch job that contains two chunk steps, a task step and a decision element. The job starts with chunk step A, continues with chunk step B, and then decision element D evaluates condition 1. The condition is based on the status of step B. If condition 1 is true, the job terminates; otherwise the job continues with step C and then the job ends."></span></p>