12

I am very new to Jersey and I did a search but unable to figure out whether Is there a way in jersey client to use connection pooling instead of creating a connection each and every time we are sending a new request.

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

This is what I'm doing 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 highly appreciable,Expecting code snippet. Thanks in advance.

3
  • I think you can't: HTTP send you a request and expects a response and after it the communication conclude... You may need to open a socket...
    – inigoD
    Aug 21, 2014 at 11:25
  • @inigoD it's possible in jee and Apache-http client, Just i want to know whether it's possible in Jersey or not.
    – lambodar
    Aug 21, 2014 at 12:32
  • Doesn't look like there is a way to create a connection pool with jersey alone. Sep 18, 2020 at 1:50

1 Answer 1

14

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.