编程语言
首页 > 编程语言> > java Jersey 2.1客户端线程安全吗?

java Jersey 2.1客户端线程安全吗?

作者:互联网

Documentation for jersey 2.0 says

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版中仍然是线程安全的吗?我在docs for 2.1.找不到有关线程安全的信息

解决方法:

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

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

标签:java,jersey,jersey-2-0,thread-safety,jersey-client
来源: https://codeday.me/bug/20190928/1827380.html