Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye authored and wilkinsona committed Sep 15, 2023
1 parent 8599f8e commit 8f4ccb0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Spec getSpec() {
public static class Spec {

/**
* Sub-protocol to use in websocket handshake signature.
* Sub-protocols to use in websocket handshake signature.
*/
private String protocols;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand All @@ -49,7 +50,6 @@
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;

Expand Down Expand Up @@ -161,9 +161,9 @@ void simpleAsyncTaskSchedulerBuilderShouldApplyCustomizers() {
.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);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -94,11 +91,10 @@ public SimpleAsyncTaskSchedulerBuilder virtualThreads(Boolean virtualThreads) {
}

/**
* 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...)
Expand All @@ -109,14 +105,13 @@ public SimpleAsyncTaskSchedulerBuilder customizers(SimpleAsyncTaskSchedulerCusto
}

/**
* 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) {
Expand All @@ -126,10 +121,9 @@ public SimpleAsyncTaskSchedulerBuilder customizers(
}

/**
* 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...)
Expand All @@ -140,13 +134,12 @@ public SimpleAsyncTaskSchedulerBuilder additionalCustomizers(SimpleAsyncTaskSche
}

/**
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.boot.task;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Set;

Expand All @@ -25,7 +24,6 @@
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;
Expand Down Expand Up @@ -59,11 +57,7 @@ void concurrencyLimitShouldApply() {
@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
Expand Down

0 comments on commit 8f4ccb0

Please sign in to comment.