Jersey Client Connection Pool

I am very new to Jersey and I did a search, but could not figure out if there is a way for the jersey client to use the connection pool instead of creating a connection every time we send a new request.

The whole idea is to reuse a set of connections from a pool that will save lots or a resource. FYI I'm not looking for Connection: keep-alive .

This is what I do now

public void postData() { Client client = new Client(); WebResource webResource = client.resource("http://SomeService.com/.."); ClientResponse response = webResource.accept("text/plain").get(ClientResponse.class); System.out.println(response.getStatus()); System.out.println(response.getEntity(String.class)); } 

Any help is very noticeable, expecting a piece of code. Thanks in advance.

+8
source share
1 answer

You can configure the Jersey client to use Apache HttpClient with the connection pool. Details on how to do this can be found in this blog post . Please note that the post itself covers Jersey 2.x, but there is a gist in the comments for Jersey 1.x.

+13
source

Source: https://habr.com/ru/post/1200825/


All Articles