Spring Batch How to set the time interval between each call in the Chunk chain

Command

I am making a technical poc for reading records from a flat file and inserting data into a database.

I am using the chunk task and completing this task with spring batch admin successfully.

I have to implement a retry policy along with a function to set the time interval between each attempt. I am stuck with setting a time interval between each attempt, since the cartridge does not support it directly. Is there any work for this?

My code

<batch:job id="importDataJob" job-repository="jobRepository"> <batch:step id="importDataStep"> <batch:tasklet transaction-manager="transactionManager"> <batch:chunk reader="dataReader" writer="dataWriter" commit-interval="1" retry-limit="3"> <batch:retryable-exception-classes> <batch:include class="javax.naming.ServiceUnavailableException" /> </batch:retryable-exception-classes> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> 
+6
source share
1 answer

In your case, the configuration will look like this:

Spring Package 2.x

 <bean id="stepParent" class="org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean" abstract="true"> <property name="backOffPolicy"> <bean class="org.springframework.batch.retry.backoff.FixedBackOffPolicy" <property name="backOffPeriod" value="2000" /> </bean> </property> </bean> <batch:job id="importDataJob" job-repository="jobRepository"> <batch:step id="importDataStep" parent="stepParent"> ... </batch:step> </batch:job> 

Unfortunately, the batch namespace does not support setting backOffPolicy directly on step , see BATCH-1441 .

Spring Package 3.0

In Spring Batch 3.0, some classes have moved to other packages. This is a fragment of the configuration:

 <bean id="stepParent" class="org.springframework.batch.core.step.factory.FaultTolerantStepFactoryBean" abstract="true"> <property name="backOffPolicy"> <bean class="org.springframework.retry.backoff.FixedBackOffPolicy"> <property name="backOffPeriod" value="2000"/> </bean> </property> </bean> 
+5
source

Source: https://habr.com/ru/post/914319/


All Articles