Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection pooling using jersey client

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.

like image 976
lambodar Avatar asked Aug 21 '14 10:08

lambodar


1 Answers

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.

like image 107
Chris H. Avatar answered Sep 20 '22 00:09

Chris H.