Details
-
Enhancement
-
Resolution: Done
-
Major
-
None
-
None
Description
In comments of ApacheHttpAsyncClient4Engine in RestEasy code, it reads:
Again, there must be no blocking IO inside InvocationCallback! (If you are wondering why not to allow blocking calls by wrapping InvocationCallbacks in extra threads: Because then the main advantage of async IO, less threading, is lost.)
I agree with the statement. Wrapping blocking calls in extra threads is not the best way.
However, in the same code base, I see CompletionStageRxInvokerImpl has the following logic:
@Override public CompletionStage<Response> get() { if (executor == null) { return CompletableFuture.supplyAsync(() -> builder.get()); } else { return CompletableFuture.supplyAsync(() -> builder.get(), executor); } }
`builder.get()` in the above code is blocking.
I believe the limitation comes from JAX-RS spec, because it passes `SyncInvoker` to `RxInvokerProvider`. Also, `async` methods returning `java.util.concurrent.Future` instead of `java.util.concurrent.CompletionStage` puts limitations.
I think the above problem can be worked around by using `InvocationCallback` to complete/fail a `CompletableFuture`.
Here is the PR which I think should provide more details: https://github.com/resteasy/Resteasy/pull/1950
I will very much appreciate if you can share your comments/feedback.