Merge pull request #37393 from izeye

* gh-37393:
  Polish

Closes gh-37393
This commit is contained in:
Andy Wilkinson
2023-09-15 13:32:23 +01:00
5 changed files with 24 additions and 37 deletions

View File

@@ -130,7 +130,7 @@ public class RSocketProperties {
public static class Spec {
/**
* Sub-protocol to use in websocket handshake signature.
* Sub-protocols to use in websocket handshake signature.
*/
private String protocols;

View File

@@ -26,6 +26,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
@@ -49,7 +50,6 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -161,9 +161,9 @@ class TaskSchedulingAutoConfigurationTests {
.run((context) -> {
assertThat(context).hasSingleBean(SimpleAsyncTaskSchedulerBuilder.class);
SimpleAsyncTaskSchedulerBuilder builder = context.getBean(SimpleAsyncTaskSchedulerBuilder.class);
Set<SimpleAsyncTaskSchedulerCustomizer> customizers = (Set<SimpleAsyncTaskSchedulerCustomizer>) ReflectionTestUtils
.getField(builder, "customizers");
assertThat(customizers).as("SimpleAsyncTaskSchedulerBuilder.customizers").contains(customizer);
assertThat(builder).extracting("customizers")
.asInstanceOf(InstanceOfAssertFactories.collection(SimpleAsyncTaskSchedulerCustomizer.class))
.containsExactly(customizer);
});
}

View File

@@ -36,7 +36,7 @@ Those default settings can be fine-tuned using the `spring.task.execution` names
This changes the thread pool to use a bounded queue so that when the queue is full (100 tasks), the thread pool increases to maximum 16 threads.
Shrinking of the pool is more aggressive as threads are reclaimed when they are idle for 10 seconds (rather than 60 seconds by default).
A scheduler can also be auto-configured if need to be associated to scheduled task execution (using `@EnableScheduling` for instance).
A scheduler can also be auto-configured if it needs to be associated with scheduled task execution (using `@EnableScheduling` for instance).
When virtual threads are enabled (using Java 21+ and configprop:spring.threads.virtual.enabled[] set to `true`) this will be a `SimpleAsyncTaskScheduler` that uses virtual threads.
Otherwise, it will be a `ThreadPoolTaskScheduler` with sensible defaults.

View File

@@ -49,10 +49,7 @@ public class SimpleAsyncTaskSchedulerBuilder {
private final Set<SimpleAsyncTaskSchedulerCustomizer> customizers;
public SimpleAsyncTaskSchedulerBuilder() {
this.threadNamePrefix = null;
this.customizers = null;
this.concurrencyLimit = null;
this.virtualThreads = null;
this(null, null, null, null);
}
private SimpleAsyncTaskSchedulerBuilder(String threadNamePrefix, Integer concurrencyLimit, Boolean virtualThreads,
@@ -94,11 +91,10 @@ public class SimpleAsyncTaskSchedulerBuilder {
}
/**
* Set the {@link SimpleAsyncTaskSchedulerCustomizer
* threadPoolTaskSchedulerCustomizers} that should be applied to the
* {@link SimpleAsyncTaskScheduler}. Customizers are applied in the order that they
* were added after builder configuration has been applied. Setting this value will
* replace any previously configured customizers.
* Set the {@link SimpleAsyncTaskSchedulerCustomizer customizers} that should be
* applied to the {@link SimpleAsyncTaskScheduler}. Customizers are applied in the
* order that they were added after builder configuration has been applied. Setting
* this value will replace any previously configured customizers.
* @param customizers the customizers to set
* @return a new builder instance
* @see #additionalCustomizers(SimpleAsyncTaskSchedulerCustomizer...)
@@ -109,14 +105,13 @@ public class SimpleAsyncTaskSchedulerBuilder {
}
/**
* Set the {@link SimpleAsyncTaskSchedulerCustomizer
* threadPoolTaskSchedulerCustomizers} that should be applied to the
* {@link SimpleAsyncTaskScheduler}. Customizers are applied in the order that they
* were added after builder configuration has been applied. Setting this value will
* replace any previously configured customizers.
* Set the {@link SimpleAsyncTaskSchedulerCustomizer customizers} that should be
* applied to the {@link SimpleAsyncTaskScheduler}. Customizers are applied in the
* order that they were added after builder configuration has been applied. Setting
* this value will replace any previously configured customizers.
* @param customizers the customizers to set
* @return a new builder instance
* @see #additionalCustomizers(SimpleAsyncTaskSchedulerCustomizer...)
* @see #additionalCustomizers(Iterable)
*/
public SimpleAsyncTaskSchedulerBuilder customizers(
Iterable<? extends SimpleAsyncTaskSchedulerCustomizer> customizers) {
@@ -126,10 +121,9 @@ public class SimpleAsyncTaskSchedulerBuilder {
}
/**
* Add {@link SimpleAsyncTaskSchedulerCustomizer threadPoolTaskSchedulerCustomizers}
* that should be applied to the {@link SimpleAsyncTaskScheduler}. Customizers are
* applied in the order that they were added after builder configuration has been
* applied.
* Add {@link SimpleAsyncTaskSchedulerCustomizer customizers} that should be applied
* to the {@link SimpleAsyncTaskScheduler}. Customizers are applied in the order that
* they were added after builder configuration has been applied.
* @param customizers the customizers to add
* @return a new builder instance
* @see #customizers(SimpleAsyncTaskSchedulerCustomizer...)
@@ -140,13 +134,12 @@ public class SimpleAsyncTaskSchedulerBuilder {
}
/**
* Add {@link SimpleAsyncTaskSchedulerCustomizer threadPoolTaskSchedulerCustomizers}
* that should be applied to the {@link SimpleAsyncTaskScheduler}. Customizers are
* applied in the order that they were added after builder configuration has been
* applied.
* Add {@link SimpleAsyncTaskSchedulerCustomizer customizers} that should be applied
* to the {@link SimpleAsyncTaskScheduler}. Customizers are applied in the order that
* they were added after builder configuration has been applied.
* @param customizers the customizers to add
* @return a new builder instance
* @see #customizers(SimpleAsyncTaskSchedulerCustomizer...)
* @see #customizers(Iterable)
*/
public SimpleAsyncTaskSchedulerBuilder additionalCustomizers(
Iterable<? extends SimpleAsyncTaskSchedulerCustomizer> customizers) {

View File

@@ -16,7 +16,6 @@
package org.springframework.boot.task;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Set;
@@ -25,7 +24,6 @@ import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -59,11 +57,7 @@ class SimpleAsyncTaskSchedulerBuilderTests {
@EnabledForJreRange(min = JRE.JAVA_21)
void virtualThreadsShouldApply() {
SimpleAsyncTaskScheduler scheduler = this.builder.virtualThreads(true).build();
Field field = ReflectionUtils.findField(SimpleAsyncTaskScheduler.class, "virtualThreadDelegate");
assertThat(field).as("SimpleAsyncTaskScheduler.virtualThreadDelegate").isNotNull();
field.setAccessible(true);
Object virtualThreadDelegate = ReflectionUtils.getField(field, scheduler);
assertThat(virtualThreadDelegate).as("SimpleAsyncTaskScheduler.virtualThreadDelegate").isNotNull();
assertThat(scheduler).extracting("virtualThreadDelegate").isNotNull();
}
@Test