BATCH-619: Updated documentation to be accurate with latest changes to skip and retry.
This commit is contained in:
@@ -1077,13 +1077,13 @@
|
||||
Usually these bad records are logged as well, which will be covered
|
||||
later when discussing listeners. Configuring skip handling requires
|
||||
using a new factory bean:
|
||||
<classname>SkipLimitStepFactoryBean</classname><programlisting> <bean id="skipSample" parent="simpleStep"
|
||||
<classname>SkipLimitStepFactoryBean</classname><programlisting> <bean id="skipSample"
|
||||
class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean">
|
||||
<property name="skipLimit" value="10" />
|
||||
<property name="itemReader" ref="flatFileItemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="skippableExceptionClasses"
|
||||
value="org.springframework.batch.item.file.FlatFileParseException">
|
||||
<emphasis role="bold"><property name="skippableExceptionClasses"
|
||||
value="org.springframework.batch.item.file.FlatFileParseException"></emphasis>
|
||||
</property>
|
||||
</bean> </programlisting></para>
|
||||
|
||||
@@ -1095,6 +1095,31 @@
|
||||
only incremented on writes (regardless of success or failure).</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<para>One problem with the example above is that any other exception
|
||||
besides a <classname>FlatFileParseException</classname> will cause the
|
||||
<classname>Job</classname> to fail. In certain scenarios this may be
|
||||
the correct behaviour, however, in certain scenarios it may be easier
|
||||
to identify which exceptions should cause failure and skip everything
|
||||
else:<programlisting> <bean id="skipSample"
|
||||
class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean">
|
||||
<property name="skipLimit" value="10" />
|
||||
<property name="itemReader" ref="flatFileItemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<emphasis role="bold"><property name="skippableExceptionClasses"
|
||||
value="java.lang.Exception"></emphasis>
|
||||
<emphasis role="bold"><property name="fatalExceptionClasses"
|
||||
value="java.io.FileNotFoundException"></emphasis>
|
||||
</property>
|
||||
</befan></programlisting></para>
|
||||
|
||||
<para>By setting the skippable exceptions to
|
||||
<classname>java.lang.Exception</classname>, any exception that is
|
||||
thrown will be skipped. However, the second list,
|
||||
'fatalExceptionClasses', contains specific exceptions that should be
|
||||
fatal if encountered.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Configuring Retry Logic</title>
|
||||
|
||||
@@ -1107,16 +1132,14 @@
|
||||
<classname>DeadlockLoserDataAccessException</classname>, which
|
||||
indicates that the current process has attempted to update a record
|
||||
that another process holds a lock on, waiting and trying again might
|
||||
result in success. In this case, a
|
||||
<classname>StatefulRetryStepFactoryBean</classname> should be
|
||||
used:</para>
|
||||
result in success. In this case, retry should be configured:</para>
|
||||
|
||||
<programlisting> <bean id="step1" parent="simpleStep"
|
||||
class="org.springframework.batch.core.step.item.StatefulRetryStepFactoryBean">
|
||||
<programlisting> <bean id="step1"
|
||||
class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean">
|
||||
<property name="itemReader" ref="itemGenerator" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="retryLimit" value="3" />
|
||||
<property name="retryableExceptionClasses" value="org.springframework.dao.DeadlockLoserDataAccessException" />
|
||||
<emphasis role="bold"><property name="retryLimit" value="3" />
|
||||
<property name="retryableExceptionClasses" value="org.springframework.dao.DeadlockLoserDataAccessException" /></emphasis>
|
||||
</bean></programlisting>
|
||||
|
||||
<para>The StatefulRetryStepFactoryBean requires a limit for the number
|
||||
@@ -1124,6 +1147,33 @@
|
||||
that are 'retryable'.</para>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Controlling rollback</title>
|
||||
|
||||
<para>By default, regardless of retry or skip, any exceptions thrown
|
||||
from the <classname>ItemWriter</classname> will cause the transaction
|
||||
controlled by the <classname>Step</classname> to rollback. If skip is
|
||||
configured as described above, exceptions thrown from the
|
||||
<classname>ItemReader</classname> will not cause a rollback. However,
|
||||
there are many scenarios in which exceptions thrown from the
|
||||
<classname>ItemWriter</classname> should not cause a rollback because
|
||||
no action has taken place to invalidate the transaction. For this
|
||||
reason, the SkipLimitStepFactoryBean can be configured with a list of
|
||||
exceptions that should not cause rollback:</para>
|
||||
|
||||
<programlisting> <bean id="step2"
|
||||
class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean">
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="skipLimit" value="1" />
|
||||
<emphasis role="bold"><property name="noRollbackForExceptionClasses"
|
||||
value="org.springframework.batch.item.validator.ValidationException" /></emphasis>
|
||||
<property name="itemReader"
|
||||
ref="tradeSqlItemReader" />
|
||||
<property name="itemWriter"
|
||||
ref="itemTrackingWriter" />
|
||||
</bean></programlisting>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<title>Registering ItemStreams with the Step</title>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user