mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-24 10:19:03 +00:00
Merge branch '4.0.x'
Closes gh-48990
This commit is contained in:
+1
-2
@@ -286,8 +286,7 @@ public class JettyServerProperties {
|
||||
private Integer selectors = -1;
|
||||
|
||||
/**
|
||||
* Maximum number of threads. Doesn't have an effect if virtual threads are
|
||||
* enabled.
|
||||
* Maximum number of threads.
|
||||
*/
|
||||
private Integer max = 200;
|
||||
|
||||
|
||||
+30
@@ -18,8 +18,10 @@ package org.springframework.boot.jetty.autoconfigure;
|
||||
|
||||
import org.eclipse.jetty.util.VirtualThreads;
|
||||
import org.eclipse.jetty.util.thread.VirtualThreadPool;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.boot.jetty.ConfigurableJettyWebServerFactory;
|
||||
import org.springframework.boot.jetty.autoconfigure.JettyServerProperties.Threads;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -34,11 +36,39 @@ import org.springframework.util.Assert;
|
||||
public class JettyVirtualThreadsWebServerFactoryCustomizer
|
||||
implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory>, Ordered {
|
||||
|
||||
private final @Nullable JettyServerProperties serverProperties;
|
||||
|
||||
/**
|
||||
* Create a new JettyVirtualThreadsWebServerFactoryCustomizer.
|
||||
* @deprecated since 4.0.3 for removal in 4.3.0 in favor of
|
||||
* {@link #JettyVirtualThreadsWebServerFactoryCustomizer(JettyServerProperties)}
|
||||
*/
|
||||
@Deprecated(since = "4.0.3", forRemoval = true)
|
||||
// Suppress the null passing here as we don't want to put @Nullable on the
|
||||
// JettyServerProperties in the other constructor
|
||||
@SuppressWarnings("NullAway")
|
||||
public JettyVirtualThreadsWebServerFactoryCustomizer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JettyVirtualThreadsWebServerFactoryCustomizer.
|
||||
* @param serverProperties the server properties
|
||||
*/
|
||||
public JettyVirtualThreadsWebServerFactoryCustomizer(JettyServerProperties serverProperties) {
|
||||
this.serverProperties = serverProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableJettyWebServerFactory factory) {
|
||||
Assert.state(VirtualThreads.areSupported(), "Virtual threads are not supported");
|
||||
VirtualThreadPool virtualThreadPool = new VirtualThreadPool();
|
||||
virtualThreadPool.setName("jetty-");
|
||||
if (this.serverProperties != null) {
|
||||
Threads properties = this.serverProperties.getThreads();
|
||||
int maxThreadCount = (properties.getMax() > 0) ? properties.getMax() : 200;
|
||||
virtualThreadPool.setMaxThreads(maxThreadCount);
|
||||
}
|
||||
factory.setThreadPool(virtualThreadPool);
|
||||
}
|
||||
|
||||
|
||||
+9
-3
@@ -38,16 +38,22 @@ import org.springframework.core.env.Environment;
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class JettyWebServerConfiguration {
|
||||
|
||||
private final JettyServerProperties jettyProperties;
|
||||
|
||||
JettyWebServerConfiguration(JettyServerProperties jettyProperties) {
|
||||
this.jettyProperties = jettyProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
JettyWebServerFactoryCustomizer jettyWebServerFactoryCustomizer(Environment environment,
|
||||
ServerProperties serverProperties, JettyServerProperties jettyProperties) {
|
||||
return new JettyWebServerFactoryCustomizer(environment, serverProperties, jettyProperties);
|
||||
ServerProperties serverProperties) {
|
||||
return new JettyWebServerFactoryCustomizer(environment, serverProperties, this.jettyProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnThreading(Threading.VIRTUAL)
|
||||
JettyVirtualThreadsWebServerFactoryCustomizer jettyVirtualThreadsWebServerFactoryCustomizer() {
|
||||
return new JettyVirtualThreadsWebServerFactoryCustomizer();
|
||||
return new JettyVirtualThreadsWebServerFactoryCustomizer(this.jettyProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-1
@@ -38,13 +38,17 @@ class JettyVirtualThreadsWebServerFactoryCustomizerTests {
|
||||
@Test
|
||||
@EnabledForJreRange(min = JRE.JAVA_21)
|
||||
void shouldConfigureVirtualThreads() {
|
||||
JettyVirtualThreadsWebServerFactoryCustomizer customizer = new JettyVirtualThreadsWebServerFactoryCustomizer();
|
||||
JettyServerProperties serverProperties = new JettyServerProperties();
|
||||
serverProperties.getThreads().setMax(100);
|
||||
JettyVirtualThreadsWebServerFactoryCustomizer customizer = new JettyVirtualThreadsWebServerFactoryCustomizer(
|
||||
serverProperties);
|
||||
ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class);
|
||||
customizer.customize(factory);
|
||||
then(factory).should().setThreadPool(assertArg((threadPool) -> {
|
||||
assertThat(threadPool).isInstanceOf(VirtualThreadPool.class);
|
||||
VirtualThreadPool virtualThreadPool = (VirtualThreadPool) threadPool;
|
||||
assertThat(virtualThreadPool.getName()).isEqualTo("jetty-");
|
||||
assertThat(virtualThreadPool.getMaxThreads()).isEqualTo(100);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user