java jersey并发,java Jersey 2.1客户端线程安全吗?

Client instances are expensive resources. It is recommended a

configured instance is reused for the creation of Web resources. The

creation of Web resources, the building of requests and receiving of

responses are guaranteed to be thread safe. Thus a Client instance and

WebResource instances may be shared between multiple threads

Is client still thread-safe in version 2.1? I cannot find information about thread safety in docs for 2.1.

解决方案

Yes, the Jersey 2.1 client is thread safe and it should be thread safe even in the future Jersey version. You can create many WebTarget from one Client instance and invoke many requests on these WebTargets and even more requests on one WebTarget instance in the same time.

The thread safety can be broken if you register your custom non-thread safe provider into a Client or a WebTaget. For example a ClientRequestFilter that is not thread safe and cannot handle more requests simultaneously. Jersey built-in providers are thread safe. Some Jersey extension providers must not be thread safe and in this case this is specified in the javadoc of a provider.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值