I have the below job configuration and then the reader code where i deliberately throw exceptions to test the retry feature. I am getting errors as below. Can someone please tell me where i am going wrong.
Code:<batch:job id="retryPolicyJob" job-repository="jobRepository"> <batch:step id="retryPolicyStep"> <batch:tasklet> <batch:chunk reader="ConnectionRetryReader" writer="CustomItemWriter" commit-interval="100" retry-policy="retryPolicy" /> </batch:tasklet> </batch:step> </batch:job> <bean id="ConnectionRetryReader" class="spring.batch.examples.retry.ConnectionRetryReader" /> <bean id="CustomItemWriter" class="spring.batch.examples.retry.CustomItemWriter" /> <bean id="retryPolicy" class="org.springframework.batch.retry.policy.ExceptionClassifierRetryPolicy"> <property name="policyMap"> <map> <entry key="org.springframework.dao.ConcurrencyFailureException"> <bean class="org.springframework.batch.retry.policy.SimpleRetryPolicy"> <property name="maxAttempts" value="2" /> </bean> </entry> <entry key="org.springframework.dao.DeadlockLoserDataAccessException"> <bean class="org.springframework.batch.retry.policy.SimpleRetryPolicy"> <property name="maxAttempts" value="3" /> </bean> </entry> </map> </property> </bean>
The reader :
Code:public class ConnectionRetryReader implements ItemReader, ItemStream { private int retryCount = 0; private T t; int currentIndex = 0; private static final String CURRENT_INDEX = "current.index"; public T read() throws Exception{ retryCount++; System.out.println("In Retry " + retryCount); if (retryCount == 2) { System.out.println("throwing ConcurrencyFailureException"); throw new org.springframework.dao.ConcurrencyFailureException("ConcurrencyFailureException thrown", new Exception()); } System.out.println("throwing DeadlockLoserDataAccessException"); throw new org.springframework.dao.DeadlockLoserDataAccessException("DeadlockLoserDataAccessException thrown", new Exception()); }
The exception i am getting is :
HTML Code:17:22:40,140 INFO main SimpleJobLauncher:179 - No TaskExecutor has been set, defaulting to synchronous executor. 17:22:40,546 INFO main SimpleJobLauncher:118 - Job: [FlowJob: [name=retryPolicyJob]] launched with the following parameters: [{}] 17:22:40,577 INFO main SimpleStepHandler:133 - Executing step: [retryPolicyStep] In Retry 1 throwing DeadlockLoserDataAccessException 17:22:40,640 ERROR main AbstractStep:212 - Encountered an error executing the step org.springframework.batch.core.step.skip.NonSkippableReadException: Non-skippable exception during read at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:104) at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:108) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:386) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264) at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) at spring.batch.examples.retry.RetryTestCommandLine.main(RetryTestCommandLine.java:9) Caused by: org.springframework.dao.DeadlockLoserDataAccessException: DeadlockLoserDataAccessException thrown; nested exception is java.lang.Exception at spring.batch.examples.retry.ConnectionRetryReader.read(ConnectionRetryReader.java:30) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90) at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:87) ... 28 more Caused by: java.lang.Exception at spring.batch.examples.retry.ConnectionRetryReader.read(ConnectionRetryReader.java:31) ... 30 more 17:22:40,655 INFO main SimpleJobLauncher:121 - Job: [FlowJob: [name=retryPolicyJob]] completed with the following parameters: [{}] and the following status: [FAILED]


Reply With Quote
