|
|
|
|
@@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.task;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
@@ -54,17 +55,21 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
|
|
|
|
|
private final Set<SimpleAsyncTaskExecutorCustomizer> customizers;
|
|
|
|
|
|
|
|
|
|
private final Duration taskTerminationTimeout;
|
|
|
|
|
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder() {
|
|
|
|
|
this(null, null, null, null, null);
|
|
|
|
|
this(null, null, null, null, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SimpleAsyncTaskExecutorBuilder(Boolean virtualThreads, String threadNamePrefix, Integer concurrencyLimit,
|
|
|
|
|
TaskDecorator taskDecorator, Set<SimpleAsyncTaskExecutorCustomizer> customizers) {
|
|
|
|
|
TaskDecorator taskDecorator, Set<SimpleAsyncTaskExecutorCustomizer> customizers,
|
|
|
|
|
Duration taskTerminationTimeout) {
|
|
|
|
|
this.virtualThreads = virtualThreads;
|
|
|
|
|
this.threadNamePrefix = threadNamePrefix;
|
|
|
|
|
this.concurrencyLimit = concurrencyLimit;
|
|
|
|
|
this.taskDecorator = taskDecorator;
|
|
|
|
|
this.customizers = customizers;
|
|
|
|
|
this.taskTerminationTimeout = taskTerminationTimeout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -74,7 +79,7 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder threadNamePrefix(String threadNamePrefix) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.taskDecorator, this.customizers);
|
|
|
|
|
this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -84,7 +89,7 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder virtualThreads(Boolean virtualThreads) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.taskDecorator, this.customizers);
|
|
|
|
|
this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -94,7 +99,7 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder concurrencyLimit(Integer concurrencyLimit) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, concurrencyLimit,
|
|
|
|
|
this.taskDecorator, this.customizers);
|
|
|
|
|
this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -104,7 +109,18 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
taskDecorator, this.customizers);
|
|
|
|
|
taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the task termination timeout.
|
|
|
|
|
* @param taskTerminationTimeout the task termination timeout
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
* @since 3.2.1
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder taskTerminationTimeout(Duration taskTerminationTimeout) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.taskDecorator, this.customizers, taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -134,7 +150,7 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) {
|
|
|
|
|
Assert.notNull(customizers, "Customizers must not be null");
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.taskDecorator, append(null, customizers));
|
|
|
|
|
this.taskDecorator, append(null, customizers), this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -162,7 +178,7 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) {
|
|
|
|
|
Assert.notNull(customizers, "Customizers must not be null");
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.taskDecorator, append(this.customizers, customizers));
|
|
|
|
|
this.taskDecorator, append(this.customizers, customizers), this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -203,6 +219,7 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
map.from(this.threadNamePrefix).whenHasText().to(taskExecutor::setThreadNamePrefix);
|
|
|
|
|
map.from(this.concurrencyLimit).to(taskExecutor::setConcurrencyLimit);
|
|
|
|
|
map.from(this.taskDecorator).to(taskExecutor::setTaskDecorator);
|
|
|
|
|
map.from(this.taskTerminationTimeout).as(Duration::toMillis).to(taskExecutor::setTaskTerminationTimeout);
|
|
|
|
|
if (!CollectionUtils.isEmpty(this.customizers)) {
|
|
|
|
|
this.customizers.forEach((customizer) -> customizer.customize(taskExecutor));
|
|
|
|
|
}
|
|
|
|
|
|