以下と同じように設定しました。しかし、例外が発生しています (後述)。助けてください。そうする目的は、失敗時にステップを再起動することです。
======================================= retryPolicyJob.xml
<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>
============================================ リーダークラスコード:
public class ConnectionRetryReader<T> implements ItemReader<T>, ItemStream {
private int retryCount = 0;
private T t;
int currentIndex = 0;
private static final String CURRENT_INDEX = "current.index";
public T read() throws Exception, UnexpectedInputException, ParseException,
NonTransientResourceException, ConnectionFailureException,
ResourceNotAvailableException {
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());
}
public void open(ExecutionContext executionContext)
throws ItemStreamException {
if (executionContext.containsKey(CURRENT_INDEX)) {
currentIndex = new Long(executionContext.getLong(CURRENT_INDEX))
.intValue();
} else {
currentIndex = 0;
}
}
public void update(ExecutionContext executionContext)
throws ItemStreamException {
executionContext.putLong(CURRENT_INDEX,
new Long(currentIndex).longValue());
}
public void close() throws ItemStreamException {
// TODO Auto-generated method stub
}
}
================================================== == 例外メッセージ:
17:22:40,140 INFO main SimpleJobLauncher:179 - TaskExecutor が設定されておらず、デフォルトで同期エグゼキューターに設定されています。 17:22:40,546 INFO main SimpleJobLauncher:118 - ジョブ: [FlowJob: [name=retryPolicyJob]] が次のパラメーターで起動されました: [{}] 17:22:40,577 INFO main SimpleStepHandler:133 - 実行ステップ: [retryPolicyStep] リトライ1で DeadlockLoserDataAccessException をスローする 17:22:40,640 ERROR main AbstractStep:212 - ステップの実行中にエラーが発生しました org.springframework.batch.core.step.skip.NonSkippableReadException: 読み取り中のスキップ不可の例外 org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:104) で org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:108) で org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) で org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) で org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) で org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103) で org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68) で org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:386) で org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) で org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264) で org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76) で org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) で org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) で org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) で org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250)で org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) で org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) で org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) で org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) で org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) で org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) で org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)で org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) で org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) で org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) で org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) で org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349) で org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) で spring.batch.examples.retry.RetryTestCommandLine.main(RetryTestCommandLine.java:9) で 原因: org.springframework.dao.DeadlockLoserDataAccessException: DeadlockLoserDataAccessException throw; ネストされた例外は java.lang.Exception です spring.batch.examples.retry.ConnectionRetryReader.read(ConnectionRetryReader.java:30) で org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90) で org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:87) で ... 28以上 原因: java.lang.Exception spring.batch.examples.retry.ConnectionRetryReader.read(ConnectionRetryReader.java:31) で ... 30以上 17:22:40,655 INFO main SimpleJobLauncher:121 - ジョブ: [FlowJob: [name=retryPolicyJob]] が次のパラメータで完了しました: [{}] および次のステータス: [FAILED]