diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketProperties.java index dd16caad71..10096dfdda 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/rsocket/RSocketProperties.java @@ -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; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java index 5d0cd515e8..ca211b30b9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/task/TaskSchedulingAutoConfigurationTests.java @@ -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 customizers = (Set) ReflectionTestUtils - .getField(builder, "customizers"); - assertThat(customizers).as("SimpleAsyncTaskSchedulerBuilder.customizers").contains(customizer); + assertThat(builder).extracting("customizers") + .asInstanceOf(InstanceOfAssertFactories.collection(SimpleAsyncTaskSchedulerCustomizer.class)) + .containsExactly(customizer); }); } diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/task-execution-and-scheduling.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/task-execution-and-scheduling.adoc index 1b5e8130d5..547be87514 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/task-execution-and-scheduling.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/task-execution-and-scheduling.adoc @@ -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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilder.java index 6c478250e1..e5dab60b1e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilder.java @@ -49,10 +49,7 @@ public class SimpleAsyncTaskSchedulerBuilder { private final Set 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 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 customizers) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilderTests.java index 440a42c0d6..9b4e7da12c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/task/SimpleAsyncTaskSchedulerBuilderTests.java @@ -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