Issue #1516 - making WebSocket started thread pools have identifying names
This commit is contained in:
parent
2679715a30
commit
c75e3c19d9
|
@ -51,7 +51,7 @@ public class DelayedStartClientTest
|
|||
assertThat("Container", container, notNullValue());
|
||||
|
||||
List<String> threadNames = getThreadNames();
|
||||
assertThat("Threads", threadNames, not(hasItem(containsString("SimpleContainerScope.Executor@"))));
|
||||
assertThat("Threads", threadNames, not(hasItem(containsString("WebSocketContainer@"))));
|
||||
assertThat("Threads", threadNames, not(hasItem(containsString("HttpClient@"))));
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue