February 2014
Beginner
1248 pages
62h 25m
English
Class CompletableFuture implements interface Future, so we can obtain the asynchronous tasks’ results by calling Future method get (lines 44–45). These are blocking calls—they cause the main thread to wait until the asynchronous tasks complete and return their results. In our case, the results are TimeData objects. Once both tasks return, lines 46–47 pass both TimeData objects to method calculateTime (lines 91–104) to get the total calculation time in seconds. Then, lines 48–49 display the total calculation time for the asynchronous Fibonacci calculations. Finally, lines 52–55 calculate and display the percentage difference in execution time for the synchronous and asynchronous calculations.
Read now
Unlock full access