|
|
|
@ -50,10 +50,10 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
|
|
|
|
|
private final String threadNamePrefix;
|
|
|
|
|
|
|
|
|
|
private final Integer concurrencyLimit;
|
|
|
|
|
|
|
|
|
|
private final boolean rejectTasksWhenLimitReached;
|
|
|
|
|
|
|
|
|
|
private final Integer concurrencyLimit;
|
|
|
|
|
|
|
|
|
|
private final TaskDecorator taskDecorator;
|
|
|
|
|
|
|
|
|
|
private final Set<SimpleAsyncTaskExecutorCustomizer> customizers;
|
|
|
|
@ -61,16 +61,16 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
private final Duration taskTerminationTimeout;
|
|
|
|
|
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder() {
|
|
|
|
|
this(null, null, null, false, null, null, null);
|
|
|
|
|
this(null, null, false, null, null, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SimpleAsyncTaskExecutorBuilder(Boolean virtualThreads, String threadNamePrefix, Integer concurrencyLimit,
|
|
|
|
|
boolean rejectTasksWhenLimitReached, TaskDecorator taskDecorator,
|
|
|
|
|
private SimpleAsyncTaskExecutorBuilder(Boolean virtualThreads, String threadNamePrefix,
|
|
|
|
|
boolean rejectTasksWhenLimitReached, Integer concurrencyLimit, TaskDecorator taskDecorator,
|
|
|
|
|
Set<SimpleAsyncTaskExecutorCustomizer> customizers, Duration taskTerminationTimeout) {
|
|
|
|
|
this.virtualThreads = virtualThreads;
|
|
|
|
|
this.threadNamePrefix = threadNamePrefix;
|
|
|
|
|
this.concurrencyLimit = concurrencyLimit;
|
|
|
|
|
this.rejectTasksWhenLimitReached = rejectTasksWhenLimitReached;
|
|
|
|
|
this.concurrencyLimit = concurrencyLimit;
|
|
|
|
|
this.taskDecorator = taskDecorator;
|
|
|
|
|
this.customizers = customizers;
|
|
|
|
|
this.taskTerminationTimeout = taskTerminationTimeout;
|
|
|
|
@ -82,8 +82,9 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder threadNamePrefix(String threadNamePrefix) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.concurrencyLimit, this.taskDecorator, this.customizers,
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -92,8 +93,24 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder virtualThreads(Boolean virtualThreads) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(virtualThreads, this.threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.concurrencyLimit, this.taskDecorator, this.customizers,
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set whether to reject tasks when the concurrency limit has been reached. By default
|
|
|
|
|
* {@code false} to block the caller until the submission can be accepted. Switch to
|
|
|
|
|
* {@code true} for immediate rejection instead.
|
|
|
|
|
* @param rejectTasksWhenLimitReached whether to reject tasks when the concurrency
|
|
|
|
|
* limit has been reached
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
* @since 3.5.0
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached(boolean rejectTasksWhenLimitReached) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix,
|
|
|
|
|
rejectTasksWhenLimitReached, this.concurrencyLimit, this.taskDecorator, this.customizers,
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -102,20 +119,9 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder concurrencyLimit(Integer concurrencyLimit) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Specify whether to reject tasks when the concurrency limit has been reached.
|
|
|
|
|
* @param rejectTasksWhenLimitReached whether to reject tasks when the concurrency
|
|
|
|
|
* limit has been reached
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
* @since 3.5.0
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached(boolean rejectTasksWhenLimitReached) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
rejectTasksWhenLimitReached, this.taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, concurrencyLimit, this.taskDecorator, this.customizers,
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -124,8 +130,9 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
* @return a new builder instance
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, taskDecorator, this.customizers, this.taskTerminationTimeout);
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.concurrencyLimit, taskDecorator, this.customizers,
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -135,8 +142,9 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
* @since 3.2.1
|
|
|
|
|
*/
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder taskTerminationTimeout(Duration taskTerminationTimeout) {
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.taskDecorator, this.customizers, taskTerminationTimeout);
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.concurrencyLimit, this.taskDecorator, this.customizers,
|
|
|
|
|
taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -165,8 +173,8 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder customizers(
|
|
|
|
|
Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) {
|
|
|
|
|
Assert.notNull(customizers, "'customizers' must not be null");
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.taskDecorator, append(null, customizers),
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.concurrencyLimit, this.taskDecorator, append(null, customizers),
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -194,9 +202,9 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
public SimpleAsyncTaskExecutorBuilder additionalCustomizers(
|
|
|
|
|
Iterable<? extends SimpleAsyncTaskExecutorCustomizer> customizers) {
|
|
|
|
|
Assert.notNull(customizers, "'customizers' must not be null");
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix, this.concurrencyLimit,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.taskDecorator, append(this.customizers, customizers),
|
|
|
|
|
this.taskTerminationTimeout);
|
|
|
|
|
return new SimpleAsyncTaskExecutorBuilder(this.virtualThreads, this.threadNamePrefix,
|
|
|
|
|
this.rejectTasksWhenLimitReached, this.concurrencyLimit, this.taskDecorator,
|
|
|
|
|
append(this.customizers, customizers), this.taskTerminationTimeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -235,8 +243,8 @@ public class SimpleAsyncTaskExecutorBuilder {
|
|
|
|
|
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
|
|
|
|
map.from(this.virtualThreads).to(taskExecutor::setVirtualThreads);
|
|
|
|
|
map.from(this.threadNamePrefix).whenHasText().to(taskExecutor::setThreadNamePrefix);
|
|
|
|
|
map.from(this.concurrencyLimit).to(taskExecutor::setConcurrencyLimit);
|
|
|
|
|
map.from(this.rejectTasksWhenLimitReached).to(taskExecutor::setRejectTasksWhenLimitReached);
|
|
|
|
|
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)) {
|
|
|
|
|