February 2014
Beginner
1248 pages
62h 25m
English
Lines 38–41 in main launch the asynchronous Fibonacci calculations in separate threads. CompletableFuture static method supplyAsync executes an asynchronous task that returns a value. The method receives as its argument an object that implements interface Sup- plier—in this case, we use a lambdas with empty parameter lists to invoke startFibonacci(45) (line 39) and startFibonacci(44) (line 41). The compiler infers that supplyAsync returns a CompletableFuture<TimeData> because method startFibonacci returns type TimeData. Class CompletableFuture also provides static method runAsync to execute an asynchronous task that does not return a result—this method receives a Runnable.
Read now
Unlock full access