mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Use milliseconds when configuring awaitTerminationPeriod
Prior to this change, TaskExecutorBuilder used seconds as its precision to map the awaitTerminationPeriod value. This caused a loss of millisecond information in the period. This commit fixes the loss by converting the period to millisecond and using setAwaitTerminationMillis to configure the executor. See gh-22604
This commit is contained in:
parent
d9b61c4aaa
commit
685a6116d1
@ -308,7 +308,7 @@ public class TaskExecutorBuilder {
|
||||
map.from(this.keepAlive).asInt(Duration::getSeconds).to(taskExecutor::setKeepAliveSeconds);
|
||||
map.from(this.allowCoreThreadTimeOut).to(taskExecutor::setAllowCoreThreadTimeOut);
|
||||
map.from(this.awaitTermination).to(taskExecutor::setWaitForTasksToCompleteOnShutdown);
|
||||
map.from(this.awaitTerminationPeriod).asInt(Duration::getSeconds).to(taskExecutor::setAwaitTerminationSeconds);
|
||||
map.from(this.awaitTerminationPeriod).as(Duration::toMillis).to(taskExecutor::setAwaitTerminationMillis);
|
||||
map.from(this.threadNamePrefix).whenHasText().to(taskExecutor::setThreadNamePrefix);
|
||||
map.from(this.taskDecorator).to(taskExecutor::setTaskDecorator);
|
||||
if (!CollectionUtils.isEmpty(this.customizers)) {
|
||||
|
@ -65,6 +65,10 @@ class TaskExecutorBuilderTests {
|
||||
Duration period = Duration.ofMinutes(1);
|
||||
ThreadPoolTaskExecutor executor = this.builder.awaitTerminationPeriod(period).build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("awaitTerminationMillis", period.toMillis());
|
||||
|
||||
period = Duration.ofMillis(50);
|
||||
executor = this.builder.awaitTerminationPeriod(period).build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("awaitTerminationMillis", period.toMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user