In this lightning presentation, you will get an overview of the usage of the CompletableFuture that was introduced in Java 8. By attending this short session you will also get an overview of its asynchronous API, some dos and don'ts using this exciting API.
This material has been previously presented at Bucharest Technology Week by László-Róbert Albert, Chief Software Architect @Crossover.
15. albertlr.ro #BTechWeek
j.u.c.CompletionStage
• Contains 38 methods
• 36 of them has 3 forms:
public CompletionStage<?> somethingAsync(..., Executor executor);
public CompletionStage<?> somethingAsync(...);
public CompletionStage<?> something(...);
16. albertlr.ro #BTechWeek
j.u.c.CompletionStage
public CompletionStage<?> somethingAsync(..., Executor executor);
• runs action chain in executor
public CompletionStage<?> somethingAsync(...);
• Same as somethingAsync(..., ForkJoinPool.commonPool())
public CompletionStage<?> something(...);
• default execution
17. albertlr.ro #BTechWeek
j.u.c.CompletionStage
public CompletionStage<?> somethingAsync(..., Executor executor);
• runs action chain in executor
public CompletionStage<?> somethingAsync(...);
• Same as somethingAsync(..., ForkJoinPool.commonPool())
public CompletionStage<?> something(...);
• default execution
18. albertlr.ro #BTechWeek
j.u.c.CompletionStage
public CompletionStage<?> somethingAsync(..., Executor executor);
• runs action chain in executor
public CompletionStage<?> somethingAsync(...);
• Same as somethingAsync(..., ForkJoinPool.commonPool())
public CompletionStage<?> something(...);
• default execution
22. albertlr.ro #BTechWeek
j.u.c.CompletionStage
• 12 methods remain
• 9 of them has 3 forms:
Apply - function from input to R, result is a CompletableFuture<R>
Accept - consumer of input, result is a CompletableFuture<Void>
23. albertlr.ro #BTechWeek
j.u.c.CompletionStage
• 12 methods remain
• 9 of them has 3 forms:
Apply - function from input to R, result is a CompletableFuture<R>
Accept - consumer of input, result is a CompletableFuture<Void>
Run - just execute a Runnable, result is a CompletableFuture<Void>