Merge branch '3.2.x'

Closes gh-40169
This commit is contained in:
Moritz Halbritter 2024-04-04 13:05:34 +02:00
commit e9e2bc94f8
2 changed files with 13 additions and 2 deletions

View File

@ -44,7 +44,7 @@ public class JettyVirtualThreadsWebServerFactoryCustomizer
public void customize(ConfigurableJettyWebServerFactory factory) { public void customize(ConfigurableJettyWebServerFactory factory) {
Assert.state(VirtualThreads.areSupported(), "Virtual threads are not supported"); Assert.state(VirtualThreads.areSupported(), "Virtual threads are not supported");
QueuedThreadPool threadPool = JettyThreadPool.create(this.serverProperties.getJetty().getThreads()); QueuedThreadPool threadPool = JettyThreadPool.create(this.serverProperties.getJetty().getThreads());
threadPool.setVirtualThreadsExecutor(VirtualThreads.getDefaultVirtualThreadsExecutor()); threadPool.setVirtualThreadsExecutor(VirtualThreads.getNamedVirtualThreadsExecutor("jetty-"));
factory.setThreadPool(threadPool); factory.setThreadPool(threadPool);
} }

View File

@ -16,7 +16,13 @@
package org.springframework.boot.autoconfigure.web.embedded; package org.springframework.boot.autoconfigure.web.embedded;
import java.time.Duration;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
import org.awaitility.Awaitility;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange; import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE; import org.junit.jupiter.api.condition.JRE;
@ -47,7 +53,12 @@ class JettyVirtualThreadsWebServerFactoryCustomizerTests {
then(factory).should().setThreadPool(assertArg((threadPool) -> { then(factory).should().setThreadPool(assertArg((threadPool) -> {
assertThat(threadPool).isInstanceOf(QueuedThreadPool.class); assertThat(threadPool).isInstanceOf(QueuedThreadPool.class);
QueuedThreadPool queuedThreadPool = (QueuedThreadPool) threadPool; QueuedThreadPool queuedThreadPool = (QueuedThreadPool) threadPool;
assertThat(queuedThreadPool.getVirtualThreadsExecutor()).isNotNull(); Executor executor = queuedThreadPool.getVirtualThreadsExecutor();
assertThat(executor).isNotNull();
AtomicReference<String> threadName = new AtomicReference<>();
executor.execute(() -> threadName.set(Thread.currentThread().getName()));
Awaitility.await().atMost(Duration.ofSeconds(1)).untilAtomic(threadName, Matchers.notNullValue());
assertThat(threadName.get()).startsWith("jetty-");
})); }));
} }