|
|
|
|
@ -18,8 +18,10 @@ package org.springframework.boot.jetty.autoconfigure;
@@ -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;
@@ -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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|