Skip to content
Advertisement

Java HttpHandler waiting for CompletableFuture

I got the following code

JavaScript

The idea is that I make a call to another client for some information, wait for his response, and then present the data that has been received and processed.

But i am looking for a way to avoid the need for Thread.sleep to avoid possible issues with other code in the system.

Is there another way to wait for the result of the comparable future call in the WebClient, before i write the results in the handler?

Advertisement

Answer

I was able to do this using the synchronize and wait on an object i created in the client. As you can see i call a synchronize on the object on the client and put it in wait. Then on the client when it’s done i call notifyall.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement