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,并在这些 WebTarget 上调用多个请求,甚至在一个 WebTarget 实例上同时调用更多请求。
如果您将自定义的非线程安全提供程序注册到客户端或 WebTget 中,则可能会破坏线程安全。例如,非线程安全且无法同时处理更多请求的 ClientRequestFilter。 Jersey 内置提供程序是线程安全的。一些 Jersey 扩展提供程序不能是线程安全的,在这种情况下,这是在提供程序的 javadoc 中指定的。
关于java - java Jersey 2.1客户端线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18078666/