使用泽西客户端的连接池 [英] Connection pooling using jersey client

查看:112
本文介绍了使用泽西客户端的连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对泽西岛非常陌生,我进行了一次搜索,但无法弄清楚 jersey客户端中是否有一种方法可以使用连接池而不是创建连接每次我们发送新请求时.

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.

这就是我现在正在做的

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.

推荐答案

您可以配置Jersey客户端以将Apache HttpClient与连接池一起使用.有关操作方法的详细信息,请参见在此博客文章上.请注意,该帖子本身涵盖了Jersey 2.x,但是对于Jersey 1.x有一个 gist 在评论中提到.

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.

这篇关于使用泽西客户端的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆