Sobes.tech
Junior — Middle

Is calling the get method on a CompletableFuture object a blocking operation or does it work without blocking?

sobes.tech AI

Answer from AI

Calling the get() method on a CompletableFuture object is a blocking operation. This means that if the result is not yet ready, the current thread is suspended and waits until the computation is finished and the result becomes available.

If the result is already ready, get() will return it immediately without blocking.

For non-blocking retrieval of the result, methods like thenApply, thenAccept, and others can be used, which allow specifying actions to be performed after the asynchronous operation completes, without blocking the current thread.

Is calling the get method on a CompletableFuture… - sobes.tech