Skip to content

Commit 9c25019

Browse files
committed
TaskExecutor should not back off for custom ExecutorService
TaskExecutor will back off for custom Executor before this commit, now it only back off for custom TaskExecutor. Fix spring-projectsGH-44659 Signed-off-by: Yanming Zhou <[email protected]>
1 parent b6bccc1 commit 9c25019

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutorConfigurations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@
4646
class TaskExecutorConfigurations {
4747

4848
@Configuration(proxyBeanMethods = false)
49-
@ConditionalOnMissingBean(Executor.class)
49+
@ConditionalOnMissingBean(TaskExecutor.class)
5050
static class TaskExecutorConfiguration {
5151

5252
@Bean(name = { TaskExecutionAutoConfiguration.APPLICATION_TASK_EXECUTOR_BEAN_NAME,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfigurationTests.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,8 @@
1919
import java.util.concurrent.CompletableFuture;
2020
import java.util.concurrent.CountDownLatch;
2121
import java.util.concurrent.Executor;
22+
import java.util.concurrent.ExecutorService;
23+
import java.util.concurrent.Executors;
2224
import java.util.concurrent.Future;
2325
import java.util.concurrent.TimeUnit;
2426
import java.util.concurrent.atomic.AtomicReference;
@@ -210,6 +212,13 @@ void taskExecutorWhenHasCustomTaskExecutorShouldBackOff() {
210212
});
211213
}
212214

215+
@Test
216+
void taskExecutorWhenHasCustomExecutorServiceShouldNotBackOff() {
217+
this.contextRunner.withUserConfiguration(CustomExecutorServiceConfig.class).run((context) -> {
218+
assertThat(context).hasSingleBean(TaskExecutor.class);
219+
});
220+
}
221+
213222
@Test
214223
@EnabledForJreRange(min = JRE.JAVA_21)
215224
void whenVirtualThreadsAreEnabledAndCustomTaskExecutorIsDefinedThenSimpleAsyncTaskExecutorThatUsesVirtualThreadsBacksOff() {
@@ -303,12 +312,22 @@ TaskDecorator mockTaskDecorator() {
303312
static class CustomTaskExecutorConfig {
304313

305314
@Bean
306-
Executor customTaskExecutor() {
315+
TaskExecutor customTaskExecutor() {
307316
return new SyncTaskExecutor();
308317
}
309318

310319
}
311320

321+
@Configuration(proxyBeanMethods = false)
322+
static class CustomExecutorServiceConfig {
323+
324+
@Bean
325+
ExecutorService executorService() {
326+
return Executors.newSingleThreadScheduledExecutor();
327+
}
328+
329+
}
330+
312331
@Configuration(proxyBeanMethods = false)
313332
@EnableAsync
314333
static class AsyncConfiguration {

0 commit comments

Comments
 (0)