tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Kildén <karl.kil...@gmail.com>
Subject Re: Thread Safety with javax.ws.rs.client.Client and CDI
Date Tue, 25 Oct 2016 09:24:13 GMT
Hi Romain,
I understand. I will probably never reuse WebTarget but it's good to know
that I could for a static call to a service.

Thanks for the great explanation comparing to Map

Cheers





On 25 October 2016 at 09:29, Romain Manni-Bucau <rmannibucau@gmail.com>
wrote:

> Hi Karl,
>
> The question is IMHO why do you need it to be thread safe? I'll take a
> simple example: a Map. You can choose a HashMap or ConcurrenHashMap for
> instance. A HashMap is fine at runtime until you modify it. This is the
> same for the Client. If you don't modify its configuration you are safe.
>
> I think you could keep a single reference of Client (you rarely call
> register or property at runtime). It is almost the same for WebTarget until
> you set parameters (from this point you need to use a new instance per call
> without setting the thread safe property (thread.safe.client)
>
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/
> rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-10-25 9:17 GMT+02:00 Karl Kildén <karl.kilden@gmail.com>:
>
> > Hello!
> >
> > I read about it but I would just like to make sure...
> > http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-
> > RSClientAPI-ThreadSafety
> > http://cxf.apache.org/faq.html#FAQ-AreJAX-WSclientproxiesthreadsafe
> >
> > If I have a CDI @ApplicationScoped bean called Fetcher that creates the
> > Client in @PostConstruct. When I use the Fetcher from multiple threads
> the
> > Client instance itself will not be a CDI proxy (All though maybe CXF has
> > some kind of proxy impl).
> >
> > Is this safe/ good practice? Perhaps I should produce a single
> > @ApplicationScoped Client for all my Fetchers if it indeed is thread
> > safe...
> >
> > Any advice would be great
> >
> > Cheers
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message