To give a little context to my issue...
I have a Java EE web application (as a UI / client) that accesses services for data / business logic via a REST interface using the JAX-RS 2.0 client API (Resteasy implementation).
Currently I inject a new JAXRS Client instance per request using a RequestScoped CDI managed bean, the thinking being that the client app may call multiple backend resources per request and I reuse the same JAXRS Client for the whole request (although I read somewhere this may not be correct as I am potentially changing the URI for each invocation)
The documentation for JAXRS Client seems to suggest that the client is a potentially expensive operation and the app should limit the amount of connections it creates. It also seems to contradict itself and suggest the client should be closed once all the requests to a particular WebTarget are finished.
The client application could potentially support thousands of simultaneous users so creating and destroying thousands of 'expensive clients' does not seem to be the correct approach so am thinking a shared client pool is more appropriate but there doesn't seem to be any information on how this should be achieved.
All examples appear to show creating a new client for the request and a) closing it after or b) not closing it but not really explaining what happens on a second request.
Can you help provide some answers on how you think this would be solved or information on what the best practice for this approach is.
Thanks.
Official JAX-WS answer: No. According to the JAX-WS spec, the client proxies are NOT thread safe. To write portable code, you should treat them as non-thread safe and synchronize access or use a pool of instances or similar.
The rx() method call is the point from which the reactive handling kicks in. We use the exceptionally function to fluently define our exception handling scenario.
The JAX-RS client API is a Java based API used to access Web resources. It is not restricted to resources implemented using JAX-RS.
The only "best-practice" advice I've seen for avoiding either poor performance or poor memory usage patterns with a JAX-RS 2.0 client relates to the Jersey implementation of Jax-RS and so it may not be valid for RestEasy. However, I suspect that the two implementations are similar enough that the advice is portable.
Basically, my understanding is
@Singleton
.register(Class<T> componentClass)
- pretty much anything on the javax.ws.rs.core.Configurable
interface.@RequestScoped
and not Clients.javax.ws.rs.core.Configurable
interface methods.After that it's pretty much plain sailing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With