0

I am using Helidon WebClient to do API calls, I have struck upon a certain use case, I am pasting a demo of the use case.

        var request = webClient.get()
                .path("/api/users?page=2")
                .request(String.class)
                .thenAccept(res -> {
                    printThreadId("firstreq");
                    
                    System.out.println(res);
                    
                    var res2 = webClient.get()
                            .path("/api/users?page=2")
                            .request(String.class)
                            .await();

                    System.out.println(res2);

                    cf.complete(null);
                });

The problem is thread is getting blocked for endless time after the res2 call.

The solution was to use thenAcceptAsync instead of thenAccept. But, I am not able to understand, why this is the case?

  • Not familiar with Helidon and don't know how you have configured your `webClient`, but my assumption would be it uses a single thread so when `thenAccept` runs in that thread and itself tries to use `webClient` it gets stuck because the thread is already in use (by `thenAccept` itself). Whereas for `thenAcceptAsync` it probably uses a different executor with more / other threads (?). In doubt pause execution with the debugger and see where it is stuck. The proper solution might be to not call `await()` but instead return the `CompletionStage` from the nested `request` call and then chain more. – Marcono1234 Apr 23 '23 at 13:10

0 Answers0