Jax RS客户端池 [英] Jax rs client pool

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

问题描述

我正在使用jax-rs 2客户端API设置REST客户端.在api doc中说:客户端是管理客户端通信基础结构的重量级对象.初始化和处理客户端实例可能是一项相当昂贵的操作.因此,建议仅构造少量客户端应用程序中的实例."( https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/Client.html ).按照此声明,听起来客户端不是线程安全的,并且我不应该对所有请求使用单个客户端实例.

I am working on setting up a REST Client using jax-rs 2 client API. In the api doc it says "Clients are heavy-weight objects that manage the client-side communication infrastructure. Initialization as well as disposal of a Client instance may be a rather expensive operation. It is therefore advised to construct only a small number of Client instances in the application." (https://docs.oracle.com/javaee/7/api/javax/ws/rs/client/Client.html). As per this statement it sounds like Client is not thread-safe and i should not be using single Client instance for all requests.

我正在使用CXF实现,到目前为止,我还没有找到为客户端对象设置池的方法.

I am using CXF implementation, so far i didn't find a way to set up pool for Client objects.

如果有人有任何信息,请与我们分享.

If anyone has any information reg this could you please share.

谢谢.

推荐答案

默认情况下,CXF使用基于JDK中HttpURLConnection对象的传输方式来执行HTTP请求.

By default, CXF uses a transport based on the in-JDK HttpURLConnection object to perform HTTP requests.

执行连接池,允许持久连接将基础套接字连接重用于多个http请求.

Connection pooling is performed allowing persistent connections to reuse the underlying socket connection for multiple http requests.

设置这些系统属性以配置池(默认值)

Set these system properties to configure the pool(default values)

http.keepalive=true
http.maxConnections=5

增加http.maxConnections的值,以设置每个目标同时保持活动状态的最大空闲连接数.参见此链接属性properties.html的完整列表

Increment the value of http.maxConnections to set the maximum number of idle connections that will be simultaneously kept alive, per destination. See in this link the complete list of properties properties.html

本文将详细解释其工作原理

In this post are explained some detail how it works

Java HttpURLConnection和池化

还请注意,默认情况下,默认的JAX-RS客户端不是线程安全的.在正确的此处中查看限制>

Note also that the default JAX-RS client is not thread-safe by default. Check the limitations for proper use here

当您需要同时执行许多请求时,CXF还可以使用异步apache HttpAsyncClient.Ser详细信息在这里

When you need many requests executed simultaneosly CXF can also use the asynchronous apache HttpAsyncClient. Ser details here

http://cxf.apache.org/docs/asynchronous-client-http-transport.html

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

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