有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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.中找不到有关线程安全性的信息


共 (2) 个答案

  1. # 1 楼答案

    我认为,根据2.1 release notes,这方面没有任何变化,但我在文件中找不到这种变化的动机

  2. # 2 楼答案

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

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