diff --git a/docs/src/site/docbook/reference/execution.xml b/docs/src/site/docbook/reference/execution.xml index d0e5c3b25..2604bedc7 100644 --- a/docs/src/site/docbook/reference/execution.xml +++ b/docs/src/site/docbook/reference/execution.xml @@ -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: - SkipLimitStepFactoryBean <bean id="skipSample" parent="simpleStep" + SkipLimitStepFactoryBean <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"> + <property name="skippableExceptionClasses" + value="org.springframework.batch.item.file.FlatFileParseException"> </property> </bean> @@ -1095,6 +1095,31 @@ only incremented on writes (regardless of success or failure). +
+ One problem with the example above is that any other exception + besides a FlatFileParseException will cause the + Job 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: <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="java.lang.Exception"> + <property name="fatalExceptionClasses" + value="java.io.FileNotFoundException"> + </property> + </befan> + + By setting the skippable exceptions to + java.lang.Exception, any exception that is + thrown will be skipped. However, the second list, + 'fatalExceptionClasses', contains specific exceptions that should be + fatal if encountered. +
+
Configuring Retry Logic @@ -1107,16 +1132,14 @@ DeadlockLoserDataAccessException, 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 - StatefulRetryStepFactoryBean should be - used: + result in success. In this case, retry should be configured: - <bean id="step1" parent="simpleStep" - class="org.springframework.batch.core.step.item.StatefulRetryStepFactoryBean"> + <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" /> + <property name="retryLimit" value="3" /> + <property name="retryableExceptionClasses" value="org.springframework.dao.DeadlockLoserDataAccessException" /> </bean> The StatefulRetryStepFactoryBean requires a limit for the number @@ -1124,6 +1147,33 @@ that are 'retryable'.
+
+ Controlling rollback + + By default, regardless of retry or skip, any exceptions thrown + from the ItemWriter will cause the transaction + controlled by the Step to rollback. If skip is + configured as described above, exceptions thrown from the + ItemReader will not cause a rollback. However, + there are many scenarios in which exceptions thrown from the + ItemWriter 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: + + <bean id="step2" + class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean"> + <property name="commitInterval" value="2" /> + <property name="skipLimit" value="1" /> + <property name="noRollbackForExceptionClasses" + value="org.springframework.batch.item.validator.ValidationException" /> + <property name="itemReader" + ref="tradeSqlItemReader" /> + <property name="itemWriter" + ref="itemTrackingWriter" /> + </bean> +
+
Registering ItemStreams with the Step