9

Is a Jersey Client WebTarget created as following thread-safe?

WebTarget client = ClientBuilder
        .newClient(new ClientConfig(new JacksonJaxbJsonProvider(<object mapper Jackson>, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS)))
        .target("<url>");

Note that the Jackson ObjectMapper must also be thread-safe for this.

1 Answers1

6

The methods on a WebTarget that create request builders or new WebTargets are thread safe. The methods inherited from Configurable, that modify the ClientConfig may not be thread safe.

Jackson ObjectMapper is also thread safe.

So as long as you don't reconfigure the WebTarget after initialisation you should be good to go.

Gerrit
  • 173
  • 1
  • 2
  • 6
  • Great! Thank you! –  Nov 18 '17 at 21:25
  • any source for this ? – Tristan Sep 16 '21 at 09:56
  • Source for which part of my answer? The mentioned WebTarget methods don't mutate the object on which they are called, they create new objects. Hence, they are thread safe. Thread safety of ObjectMapper (except for reconfiguring) is specified, see e.g. https://fasterxml.github.io/jackson-databind/javadoc/2.7/com/fasterxml/jackson/databind/ObjectMapper.html – Gerrit Sep 17 '21 at 11:27
  • Ok, but I was hoping for some mention in Jersey 2.x doc, like it was mentionned in Jersey 1.x doc : http://javadox.com/com.sun.jersey/jersey-client/1.19/com/sun/jersey/api/client/Client.html – Tristan Sep 17 '21 at 15:20