jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.83k stars 1.91k forks source link

How to properly close the WebSocketClient@ thread problem? #11252

Open cuideyu opened 8 months ago

cuideyu commented 8 months ago

Jetty Version Jetty 9.4.53

Jetty Environment linux jetty run command: ./bin/jetty.sh run

Java Version 1.8.0_371 x64

Question I used this code to create a Websocket client connection

WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.connectToServer(this, URI.create(url));

If the server connection fails, this code will continue to be used during the reconnection. But each execution of this code creates eight threads of WebSocketClient@xxx-xxx The connection pool cannot be automatically destroyed if the connection fails. My code ContainerProvider.getWebSocketContainer(); -> org.eclipse.jetty.websocket.jsr356.ClientContainer<111 line> - > public ClientContainer() -> WebSocketClient<95 line>->public WebSocketClient() -> DefaultHttpClientProvider.get -> DefaultHttpClientProvider.newHttpClient

Reconnecting will create a new thread pool and 8 threads. How do I close this object? Can't you create a Websocket client this way in Jetty?

image_2024-01-09_01-27-57
joakime commented 8 months ago

Jetty versions older than Jetty 12 are now at End of Community Support.

You should be using Jetty 12 at this point in time.

The WebSocket layer has been reworked entirely for Jetty 12 as well.

joakime commented 8 months ago

See also https://github.com/jetty/jetty.project/issues/2659#issuecomment-421455571