diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java index 1a2fe5192..b74384e97 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/retry/policy/SimpleRetryPolicy.java @@ -16,6 +16,7 @@ package org.springframework.batch.retry.policy; +import java.util.Collections; import java.util.Map; import org.springframework.batch.classify.BinaryExceptionClassifier; @@ -42,10 +43,23 @@ import org.springframework.batch.retry.context.RetryContextSupport; */ public class SimpleRetryPolicy implements RetryPolicy { + /** + * The default limit to the number of attempts for a new policy. + */ + public final static int DEFAULT_MAX_ATTEMPTS = 3; + private volatile int maxAttempts; private BinaryExceptionClassifier retryableClassifier = new BinaryExceptionClassifier(false); + /** + * Create a {@link SimpleRetryPolicy} with the default number of retry + * attempts. + */ + public SimpleRetryPolicy() { + this(DEFAULT_MAX_ATTEMPTS, Collections., Boolean>singletonMap(Exception.class, true)); + } + /** * Create a {@link SimpleRetryPolicy} with the specified number of retry * attempts. diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java index 4ecdf82e4..3e8bb3db4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/policy/SimpleRetryPolicyTests.java @@ -34,8 +34,7 @@ public class SimpleRetryPolicyTests { @Test public void testCanRetryIfNoException() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); + SimpleRetryPolicy policy = new SimpleRetryPolicy(); RetryContext context = policy.open(null); assertTrue(policy.canRetry(context)); } @@ -55,8 +54,7 @@ public class SimpleRetryPolicyTests { @Test public void testRetryLimitInitialState() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); + SimpleRetryPolicy policy = new SimpleRetryPolicy(); RetryContext context = policy.open(null); assertTrue(policy.canRetry(context)); policy.setMaxAttempts(0); @@ -66,8 +64,7 @@ public class SimpleRetryPolicyTests { @Test public void testRetryLimitSubsequentState() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); + SimpleRetryPolicy policy = new SimpleRetryPolicy(); RetryContext context = policy.open(null); policy.setMaxAttempts(2); assertTrue(policy.canRetry(context)); @@ -79,8 +76,7 @@ public class SimpleRetryPolicyTests { @Test public void testRetryCount() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); + SimpleRetryPolicy policy = new SimpleRetryPolicy(); RetryContext context = policy.open(null); assertNotNull(context); policy.registerThrowable(context, null); @@ -104,8 +100,7 @@ public class SimpleRetryPolicyTests { @Test public void testParent() throws Exception { - SimpleRetryPolicy policy = new SimpleRetryPolicy(3, Collections - ., Boolean> singletonMap(Exception.class, true)); + SimpleRetryPolicy policy = new SimpleRetryPolicy(); RetryContext context = policy.open(null); RetryContext child = policy.open(context); assertNotSame(child, context);