Add concurrency throttle and flexible task callback to SyncTaskExecutor

Closes gh-35460
This commit is contained in:
Juergen Hoeller
2025-10-11 13:25:30 +02:00
parent 26c57cecd2
commit 8b36736344
5 changed files with 225 additions and 14 deletions
@@ -59,7 +59,8 @@ class ConcurrencyLimitTests {
futures.add(CompletableFuture.runAsync(proxy::concurrentOperation));
}
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
assertThat(target.counter).hasValue(0);
assertThat(target.current).hasValue(0);
assertThat(target.counter).hasValue(10);
}
@Test
@@ -166,10 +167,12 @@ class ConcurrencyLimitTests {
static class NonAnnotatedBean {
final AtomicInteger current = new AtomicInteger();
final AtomicInteger counter = new AtomicInteger();
public void concurrentOperation() {
if (counter.incrementAndGet() > 2) {
if (current.incrementAndGet() > 2) {
throw new IllegalStateException();
}
try {
@@ -178,7 +181,8 @@ class ConcurrencyLimitTests {
catch (InterruptedException ex) {
throw new IllegalStateException(ex);
}
counter.decrementAndGet();
current.decrementAndGet();
counter.incrementAndGet();
}
}