reuse the same WebClient instance and fix CXF-8992 if it's threadsafe#1781
reuse the same WebClient instance and fix CXF-8992 if it's threadsafe#1781dennis-yemelyanov wants to merge 1 commit intoapache:mainfrom
Conversation
When the WebClient is thread safe, it should be fine to reuse it instead of calling WebClient.fromClient(). Additionally, this fixes (at least in cases when the WebClient is thread safe) an issue due to GC: https://issues.apache.org/jira/browse/CXF-8992
| WebClient newClient; | ||
| if (targetClient != null) { | ||
| newClient = WebClient.fromClient(targetClient); | ||
| newClient = threadSafeTargetClient ? targetClient : WebClient.fromClient(targetClient); |
There was a problem hiding this comment.
@dennis-yemelyanov the usage of the new client instance is not accidental and is not about thread safety as much as the following the JAX-RS specification (please consult section "5.3 Client Targets" of the JSR-339).
There was a problem hiding this comment.
ah WebTarget must be immutable, I missed that part... I might think more if it's possible to separate the externally visible part of it (like the target URL) from internal details, so the closeable (and finalizable) part can still be reused. But I guess it won't be trivial (if possible at all).
Or we need to adjust some logic from this commit, to ensure different instances don't affect each other when finalized 5ffdb90#diff-660ab7b7b6a7b75d899f2a1cd889b168aadd5a194d2aa9fbae875c1b56891c6c
There was a problem hiding this comment.
Or..... you can make a deep copy of the WebClient inside of WebClient.fromClient() instead of a shallow copy and you never have to worry about any of this (since its an immutable copy of it)
When the
WebClientis thread safe, it should be fine to reuse it instead of callingWebClient.fromClient(). Additionally, this fixes (at least in cases when theWebClientis thread safe) an issue due to GC: https://issues.apache.org/jira/browse/CXF-8992