diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java index cc91f05e5..63fc774f0 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -42,12 +43,12 @@ public class RetryTransactionalPollingIntegrationTests implements ApplicationCon bus = (Lifecycle) applicationContext; } - private static volatile int count = 0; + private static AtomicInteger count = new AtomicInteger(0); @Before public void clearLists() { list.clear(); - count = 0; + count.set(0); } public String input() { @@ -61,7 +62,7 @@ public class RetryTransactionalPollingIntegrationTests implements ApplicationCon } public void output(String message) { - count++; + count.incrementAndGet(); logger.debug("Handled: " + message); } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java index 22d75adf3..028547355 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java @@ -3,6 +3,7 @@ package org.springframework.batch.integration.retry; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -18,7 +19,7 @@ public class SimpleService implements Service { private List expected = new ArrayList(); - private int count = 0; + private AtomicInteger count = new AtomicInteger(0); public void setExpected(List expected) { this.expected = expected; @@ -34,9 +35,9 @@ public class SimpleService implements Service { @ServiceActivator(inputChannel = "requests", outputChannel = "replies") public String process(String message) { - String result = message + ": " + (count++); + String result = message + ": " + count.incrementAndGet(); logger.debug("Handling: " + message); - if (count <= expected.size()) { + if (count.get() <= expected.size()) { processed.add(message); } if ("fail".equals(message)) {