diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java index 1430ce1e678..b72bd289851 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/DelayedStartClientTest.java @@ -51,7 +51,7 @@ public class DelayedStartClientTest assertThat("Container", container, notNullValue()); List threadNames = getThreadNames(); - assertThat("Threads", threadNames, not(hasItem(containsString("SimpleContainerScope.Executor@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@")))); } diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java index 5c82e0c0599..cc5a05fe7cb 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java @@ -37,6 +37,7 @@ import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -175,6 +176,19 @@ public class DelayedStartClientOnServerTest } } + private void assertNoHttpClientPoolThreads(List threadNames) + { + for (String threadName : threadNames) + { + if (threadName.startsWith("HttpClient@") && !threadName.endsWith("-scheduler")) + { + throw new AssertionError("Found non-scheduler HttpClient thread in <" + + threadNames.stream().collect(Collectors.joining("[", ", ", "]")) + + ">"); + } + } + } + /** * Using the Server specific techniques of JSR356, configure the WebSocketContainer. */ @@ -212,8 +226,9 @@ public class DelayedStartClientOnServerTest { server.start(); List threadNames = getThreadNames(); - assertThat("Threads", threadNames, not(hasItem(containsString("SimpleContainerScope.Executor@")))); - assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@")))); + assertNoHttpClientPoolThreads(threadNames); + assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketClient@")))); } finally { @@ -221,6 +236,7 @@ public class DelayedStartClientOnServerTest } } + @Test public void testHttpClientThreads_AfterClientConnectTo() throws Exception { @@ -237,8 +253,8 @@ public class DelayedStartClientOnServerTest String response = GET(server.getURI().resolve("/connect")); assertThat("Response", response, startsWith("Connected to ws://")); List threadNames = getThreadNames(); - assertThat("Threads", threadNames, hasItem(containsString("SimpleContainerScope.Executor@"))); - assertThat("Threads", threadNames, hasItem(containsString("HttpClient@"))); + assertNoHttpClientPoolThreads(threadNames); + assertThat("Threads", threadNames, hasItem(containsString("WebSocketContainer@"))); } finally { @@ -262,7 +278,8 @@ public class DelayedStartClientOnServerTest String response = GET(server.getURI().resolve("/connect")); assertThat("Response", response, startsWith("Connected to ws://")); List threadNames = getThreadNames(); - assertThat("Threads", threadNames, hasItem(containsString("HttpClient@"))); + assertNoHttpClientPoolThreads(threadNames); + assertThat("Threads", threadNames, hasItem(containsString("WebSocketClient@"))); } finally { @@ -286,8 +303,9 @@ public class DelayedStartClientOnServerTest String response = GET(server.getURI().resolve("/configure")); assertThat("Response", response, startsWith("Configured " + ClientContainer.class.getName())); List threadNames = getThreadNames(); - assertThat("Threads", threadNames, not(hasItem(containsString("SimpleContainerScope.Executor@")))); - assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@")))); + assertNoHttpClientPoolThreads(threadNames); + assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); + assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketClient@")))); } finally { @@ -311,8 +329,8 @@ public class DelayedStartClientOnServerTest String response = GET(server.getURI().resolve("/configure")); assertThat("Response", response, startsWith("Configured " + ServerContainer.class.getName())); List threadNames = getThreadNames(); - assertThat("Threads", threadNames, not(hasItem(containsString("SimpleContainerScope.Executor@")))); - assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@")))); + assertNoHttpClientPoolThreads(threadNames); + assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@")))); } finally { diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index bea2b75d10b..ab6494776c9 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -39,6 +39,7 @@ import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.ShutdownThread; import org.eclipse.jetty.websocket.api.Session; @@ -267,7 +268,17 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont sslContextFactory = new SslContextFactory(); } this.httpClient = new HttpClient(sslContextFactory); - this.httpClient.setExecutor(scope.getExecutor()); + Executor executor = scope.getExecutor(); + if (executor == null) + { + QueuedThreadPool threadPool = new QueuedThreadPool(); + String name = "WebSocketClient@" + hashCode(); + threadPool.setName(name); + threadPool.setDaemon(true); + executor = threadPool; + } + + this.httpClient.setExecutor(executor); addBean(this.httpClient); this.extensionRegistry = new WebSocketExtensionFactory(containerScope); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java index 5b0f7a8c7ca..a82a7565584 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java @@ -55,7 +55,7 @@ public class SimpleContainerScope extends ContainerLifeCycle implements WebSocke this.objectFactory = objectFactory; QueuedThreadPool threadPool = new QueuedThreadPool(); - String name = SimpleContainerScope.class.getSimpleName() + ".Executor@" + hashCode(); + String name = "WebSocketContainer@" + hashCode(); threadPool.setName(name); threadPool.setDaemon(true); this.executor = threadPool;