Skip to content

Tag: completable-future

How to call a method and run it asynchronously?

Is there a way to run getUsers() asynchronously only from main() in Java 8? Running getUsers() on the main thread would take 300 seconds. I wish to make it in less than 180 seconds with 4 cores. Without modifying getUsers() (the objective), running the following is still taking 300 seconds: Answer You can div…

Exception propagation in CompletableFuture (java)

How can I propagate exception encountered in the following code inside CompletableFuture.runAsync to my main thread? I want to catch the IllegalStateException in my main thread. Answer One option would be to create a Collection of Throwable objects and when the CompletableFuture completes you can add the exce…