Apply awaitTerminationPeriod to SimpleAsyncTaskScheduler

Closes gh-38530
This commit is contained in:
Moritz Halbritter
2023-11-30 10:25:08 +01:00
parent e454470bf9
commit 6744cc2887
4 changed files with 38 additions and 8 deletions

View File

@@ -152,6 +152,10 @@ class TaskSchedulingConfigurations {
builder = builder.customizers(this.taskSchedulerCustomizers.orderedStream()::iterator);
TaskSchedulingProperties.Simple simple = this.properties.getSimple();
builder = builder.concurrencyLimit(simple.getConcurrencyLimit());
TaskSchedulingProperties.Shutdown shutdown = this.properties.getShutdown();
if (shutdown.isAwaitTermination()) {
builder = builder.taskTerminationTimeout(shutdown.getAwaitTerminationPeriod());
}
return builder;
}

View File

@@ -119,13 +119,16 @@ class TaskSchedulingAutoConfigurationTests {
void simpleAsyncTaskSchedulerBuilderShouldReadProperties() {
this.contextRunner
.withPropertyValues("spring.task.scheduling.simple.concurrency-limit=1",
"spring.task.scheduling.thread-name-prefix=scheduling-test-")
"spring.task.scheduling.thread-name-prefix=scheduling-test-",
"spring.task.scheduling.shutdown.await-termination=true",
"spring.task.scheduling.shutdown.await-termination-period=30s")
.withUserConfiguration(SchedulingConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(SimpleAsyncTaskSchedulerBuilder.class);
SimpleAsyncTaskSchedulerBuilder builder = context.getBean(SimpleAsyncTaskSchedulerBuilder.class);
assertThat(builder).hasFieldOrPropertyWithValue("threadNamePrefix", "scheduling-test-");
assertThat(builder).hasFieldOrPropertyWithValue("concurrencyLimit", 1);
assertThat(builder).hasFieldOrPropertyWithValue("taskTerminationTimeout", Duration.ofSeconds(30));
});
}