问题
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
Is client still thread-safe in version 2.1? I cannot find information about thread safety in docs for 2.1.
回答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.
回答2:
I think, based on the 2.1 release notes, nothing has changed in that regard, but I cannot find the motivation for this change in documentation.
来源:https://stackoverflow.com/questions/18078666/is-java-jersey-2-1-client-thread-safe