简体   繁体   English

使用泽西客户端连接池

[英]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. 任何帮助都非常值得,Expecting代码片段。 Thanks in advance. 提前致谢。

You can configure Jersey client to use Apache HttpClient with connection pooling. 您可以将Jersey客户端配置为使用Apache HttpClient和连接池。 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. 请注意,帖子本身涵盖泽西岛2.x,但评论中提到的泽西岛1.x有一个要点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM