users@jersey.java.net

Re: [Jersey] DefaultClientConfig multi-threaded?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 14 Jan 2009 11:29:20 +0100

On Jan 13, 2009, at 9:03 PM, Matthieu Riou wrote:

> Hi,
>
> I was wondering what exactly can be shared by several threads when
> using the Jersey client API. Can a DefaultClientConfig be used by
> several threads in parrallel provided that it doesn't change?
>

When a Client is created it copies references to all the properties
from the ClientConfig. So removal or addition to properties on
DefaultClientConfig after registration will not have any effect.

You can then modify the properties on Client but it is not guaranteed
to be thread safe. When a request is built and before it is handled
the references to all the properties on the Client are copied to the
ClientRequest. Ideally i would like to have something that when
modified creates a new instance and assigns it back to the field. That
way i do not have to make unnecessary copies.

The creation of WebResource instances from Client and the building and
execution of requests on a WebResource are thread safe.

Paul.