Cometd: specifying max threads in java client

123 views Asked by At

0

The cometd documentation says that the "max threads" property can be set on both client and server... but doesn't actually provide an example. I know this can't be the actual property name since it contains a space, and when I search for 'maxThreads' I only see a server property which is clearly a different property since it has a different default value.

When I check the javadoc I can see that there's an AbstractService has a constructor argument for 'maxThreads' but I don't see the same with the BayeuxClient.

What am I missing?

If it matters we're currently using 5.0.9 but should move to 6.x once our sibling projects bump their version of jetty.

(Previously posted on salesforce.stackexchange.com without luck)

1

There are 1 answers

1
sbordet On BEST ANSWER

For HTTP:

int maxThreads = 256;

// Create and configure the HTTP client.
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP());
httpClient.setExecutor(new QueuedThreadPool(maxThreads));
httpClient.start();

// Create the BayeuxClient with the CometD HTTP transport.
BayeuxClient bayeuxClient = new BayeuxClient(cometdURL, new JettyHttpClientTransport(null, httpClient));

Similarly, all properties related to HTTP (and not to CometD) are configured in HttpClient, such as HttpClient.maxConnectionsPerDestination, etc.

For WebSocket it is similar; if you use Jetty's WebSocketClient, you pass an HttpClient (it may be shared with the HTTP transport) to WebSocketClient's constructor, and configure HTTP properties in HttpClient and WebSocket properties in WebSocketClient.