delayedExecutor() method of CompletableFuture object in Java

This method was introduced from Java 9.

Here we have two overload methods delayedExecutor(), the first method has the following syntax:

This method returns an Executor object from the default Executor object that the CompletableFuture object uses to execute the task, after the delay. And this new Executor object will do task execution.

The second is:

This method also returns an Executor object but is an Executor object that we pass into this method, after the delay. And this new Executor object will also do task execution.

For example, I want to calculate the sum of two numbers and for some conditions, I want it to happen after 2 seconds, my code will look like this:

When running the above example, you will see after 2s, the results will appear:

delayedExecutor() method of CompletableFuture object in Java

 

Add Comment