In Quarkus, rest client can be defined to return my DTO, or CompletionStage.
I have 2 endpoints to call, first I want to retrieve some JobDTO
from endpoint 1, then update it and save it back using 2nd endpoint.
I observed that:
- If I define both endpoints returning
CompletionStage<JobDTO>
, main thread will initializeexecutor-thread-0
to call endpoint 1, and thenexecutor-thread-0
hands over the work toexecutor-thread-1
to call endpoint 2 - If I define 1st to return
CompletionStage<JobDTO>
, then 2nd endpoint to returnJobDTO
, onlyexecutor-thread-0
is used, 2nd endpoint call happens on it too.
I know that in this case, by default, ForkJoinPool.commonPool
is used.
So, which is better? It's blocking I/O operation so I guess it's better to only block 1 thread if API call is slow; however I am not sure how the work stealing pool works, when I/O blocking happens.
For example if I define both to return CompletionStage
, and 1st endpoint returns fast, executor-thread-0
will quickly hand over work
to executor-thread-1
. Then, will executor-thread-0
fetch more work and hands it over to executor-thread-2
to cause more threads blocking? Or it still hands to executor-thread-1
and queuing there?
Do I have to calculate the latency of these 2 endpoints and do some calculation, and then use some custom ExecutorService?