© Fu Cheng 2018
Fu ChengExploring Java 9https://doi.org/10.1007/978-1-4842-3330-6_10

10. Concurrency

Fu Cheng
(1)
Auckland, New Zealand
 
This chapter summarizes changes related to concurrency in Java 9.

CompletableFuture

Several new methods have been added to java.util.concurrent.CompletableFuture in Java 9.

Async

The CompletableFuture<T> completeAsync(Supplier<? extends T> supplier, Executor executor) and CompletableFuture<T> completeAsync(Supplier<? extends T> supplier) methods c omplete the CompletableFuture by using an asynchronous task to invoke the Supplier to get the result. The task is executed using the provided executor or the default executor. Listing 10-1 shows examples of how to use completeAsync().
final Long v1 = new CompletableFuture<Long>().completeAsync(() ...

Get Exploring Java 9: Build Modularized Applications in Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.