Files
spring-batch/build/reference-epub-work/ch12s05.xhtml
Michael Minella 75ab909314 update
2017-03-23 10:18:33 -05:00

42 lines
4.6 KiB
HTML

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Processing Models</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch12s04.xhtml" title="Batch Properties"/><link rel="next" href="ch12s06.xhtml" title="Running a job"/></head><body><header/><section class="section" title="Processing Models" epub:type="subchapter" id="jsrProcessingModels"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Processing Models</h2></div></div></div><p>JSR-352 provides the same two basic processing models that Spring Batch does:</p><p>
</p><div class="itemizedlist" epub:type="list"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem" epub:type="list-item"><p>Item based processing - Using an <code class="classname">javax.batch.api.chunk.ItemReader</code>, an
optional <code class="classname">javax.batch.api.chunk.ItemProcessor</code>, and an
<code class="classname">javax.batch.api.chunk.ItemWriter</code>.</p></li><li class="listitem" epub:type="list-item"><p>Task based processing - Using a <code class="classname">javax.batch.api.Batchlet</code>
implementation. This processing model is the same as the
<code class="classname">org.springframework.batch.core.step.tasklet.Tasklet</code> based processing
currently available.</p></li></ul></div><p>
</p><section class="section" title="Item based processing" epub:type="division" id="d5e3942"><div class="titlepage"><div><div><h3 class="title">Item based processing</h3></div></div></div><p>Item based processing in this context is a chunk size being set by the number of items read by an
<code class="classname">ItemReader</code>. To configure a step this way, specify the
<code class="classname">item-count</code> (which defaults to 10) and optionally configure the
<code class="classname">checkpoint-policy</code> as item (this is the default).
</p><pre class="programlisting">...
&lt;step id="step1"&gt;
&lt;chunk checkpoint-policy="item" item-count="3"&gt;
&lt;reader ref="fooReader"/&gt;
&lt;processor ref="fooProcessor"/&gt;
&lt;writer ref="fooWriter"/&gt;
&lt;/chunk&gt;
&lt;/step&gt;
...</pre><p>
If item based checkpointing is chosen, an additional attribute <code class="classname">time-limit</code> is
supported. This sets a time limit for how long the number of items specified has to be processed. If
the timeout is reached, the chunk will complete with however many items have been read by then
regardless of what the <code class="classname">item-count</code> is configured to be.
</p></section><section class="section" title="Custom checkpointing" epub:type="division" id="d5e3952"><div class="titlepage"><div><div><h3 class="title">Custom checkpointing</h3></div></div></div><p>JSR-352 calls the process around the commit interval within a step "checkpointing". Item based
checkpointing is one approach as mentioned above. However, this will not be robust enough in many
cases. Because of this, the spec allows for the implementation of a custom checkpointing algorithm by
implementing the <code class="classname">javax.batch.api.chunk.CheckpointAlgorithm</code> interface. This
functionality is functionally the same as Spring Batch's custom completion policy. To use an
implementation of <code class="classname">CheckpointAlgorithm</code>, configure your step with the custom
<code class="classname">checkpoint-policy</code> as shown below where fooCheckpointer refers to an
implementation of <code class="classname">CheckpointAlgorithm</code>.
</p><pre class="programlisting">...
&lt;step id="step1"&gt;
&lt;chunk checkpoint-policy="custom"&gt;
&lt;checkpoint-algorithm ref="fooCheckpointer"/&gt;
&lt;reader ref="fooReader"/&gt;
&lt;processor ref="fooProcessor"/&gt;
&lt;writer ref="fooWriter"/&gt;
&lt;/chunk&gt;
&lt;/step&gt;
...</pre></section></section><footer/></body></html>