Skip to content

Commit

Permalink
Only apply awaitTerminationPeriod if awaitTermination is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Nov 30, 2023
1 parent 6744cc2 commit fdbd65a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading;
import org.springframework.boot.autoconfigure.task.TaskExecutionProperties.Shutdown;
import org.springframework.boot.autoconfigure.thread.Threading;
import org.springframework.boot.task.SimpleAsyncTaskExecutorBuilder;
import org.springframework.boot.task.SimpleAsyncTaskExecutorCustomizer;
Expand Down Expand Up @@ -92,7 +91,7 @@ TaskExecutorBuilder taskExecutorBuilder(TaskExecutionProperties properties,
builder = builder.maxPoolSize(pool.getMaxSize());
builder = builder.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout());
builder = builder.keepAlive(pool.getKeepAlive());
Shutdown shutdown = properties.getShutdown();
TaskExecutionProperties.Shutdown shutdown = properties.getShutdown();
builder = builder.awaitTermination(shutdown.isAwaitTermination());
builder = builder.awaitTerminationPeriod(shutdown.getAwaitTerminationPeriod());
builder = builder.threadNamePrefix(properties.getThreadNamePrefix());
Expand Down Expand Up @@ -120,7 +119,7 @@ ThreadPoolTaskExecutorBuilder threadPoolTaskExecutorBuilder(TaskExecutionPropert
builder = builder.maxPoolSize(pool.getMaxSize());
builder = builder.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout());
builder = builder.keepAlive(pool.getKeepAlive());
Shutdown shutdown = properties.getShutdown();
TaskExecutionProperties.Shutdown shutdown = properties.getShutdown();
builder = builder.awaitTermination(shutdown.isAwaitTermination());
builder = builder.awaitTerminationPeriod(shutdown.getAwaitTerminationPeriod());
builder = builder.threadNamePrefix(properties.getThreadNamePrefix());
Expand Down Expand Up @@ -177,8 +176,10 @@ private SimpleAsyncTaskExecutorBuilder builder() {
builder = builder.taskDecorator(this.taskDecorator.getIfUnique());
TaskExecutionProperties.Simple simple = this.properties.getSimple();
builder = builder.concurrencyLimit(simple.getConcurrencyLimit());
Shutdown shutdown = this.properties.getShutdown();
builder = builder.taskTerminationTimeout(shutdown.getAwaitTerminationPeriod());
TaskExecutionProperties.Shutdown shutdown = this.properties.getShutdown();
if (shutdown.isAwaitTermination()) {
builder = builder.taskTerminationTimeout(shutdown.getAwaitTerminationPeriod());
}
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void simpleAsyncTaskExecutorBuilderShouldReadProperties() {
this.contextRunner
.withPropertyValues("spring.task.execution.thread-name-prefix=mytest-",
"spring.task.execution.simple.concurrency-limit=1",
"spring.task.execution.shutdown.await-termination=true",
"spring.task.execution.shutdown.await-termination-period=30s")
.run(assertSimpleAsyncTaskExecutor((taskExecutor) -> {
assertThat(taskExecutor.getConcurrencyLimit()).isEqualTo(1);
Expand Down

0 comments on commit fdbd65a

Please sign in to comment.