diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java index 124b3081e5..b4093bc1d2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.junit.jupiter.api.Test; @@ -164,6 +165,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { } @Test + @SuppressWarnings("removal") void testThrottleLimit() { int throttleLimit = 600; @@ -174,30 +176,27 @@ void testThrottleLimit() { template.setTaskExecutor(taskExecutor); template.setThrottleLimit(throttleLimit); - final String threadName = Thread.currentThread().getName(); - final Set threadNames = new HashSet<>(); - final List items = new ArrayList<>(); - - final RepeatCallback callback = new RepeatCallback() { - @Override - public RepeatStatus doInIteration(RepeatContext context) throws Exception { - assertNotSame(threadName, Thread.currentThread().getName()); - Trade item = provider.read(); - threadNames.add(Thread.currentThread().getName() + " : " + item); - items.add("" + item); - if (item != null) { - processor.write(Chunk.of(item)); - // Do some more I/O - for (int i = 0; i < 10; i++) { - TradeItemReader provider = new TradeItemReader(resource); - provider.open(new ExecutionContext()); - while (provider.read() != null) - continue; - provider.close(); - } + String threadName = Thread.currentThread().getName(); + Set threadNames = ConcurrentHashMap.newKeySet(); + List items = Collections.synchronizedList(new ArrayList<>()); + + RepeatCallback callback = context -> { + assertNotSame(threadName, Thread.currentThread().getName()); + Trade item = provider.read(); + threadNames.add(Thread.currentThread().getName() + " : " + item); + items.add("" + item); + if (item != null) { + processor.write(Chunk.of(item)); + // Do some more I/O + for (int i = 0; i < 10; i++) { + TradeItemReader provider = new TradeItemReader(resource); + provider.open(new ExecutionContext()); + while (provider.read() != null) + continue; + provider.close(); } - return RepeatStatus.continueIf(item != null); } + return RepeatStatus.continueIf(item != null); }; template.iterate(callback);