java Jersey 2.1客户端线程安全吗? [英] Is java Jersey 2.1 client thread safe?

查看:302
本文介绍了java Jersey 2.1客户端线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对jersey 2.0的文档说


客户端实例是昂贵的资源。建议将
配置的实例重新用于创建Web资源。
创建Web资源,构建请求和接收
响应保证是线程安全的。因此,客户端实例和
WebResource实例可以在多个线程之间共享

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

客户端在2.1版中是否仍然是线程安全的?我无法在 2.1的文档。

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

推荐答案

是的,Jersey 2.1客户端是线程安全的,它应该是即使在未来的泽西版本中也是线程安全的。您可以从一个Client实例创建许多WebTarget,并在这些WebTargets上调用许多请求,同时在一个WebTarget实例上调用更多请求。

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.

可以打破线程安全性如果您将自定义非线程安全提供程序注册到客户端或WebTaget中。例如,ClientRequestFilter不是线程安全的,无法同时处理更多请求。 Jersey内置提供程序是线程安全的。一些Jersey扩展提供程序必须不是线程安全的,在这种情况下,这是在提供程序的javadoc中指定的。

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.

这篇关于java Jersey 2.1客户端线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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