From the course: Advanced Java: Threads and Concurrency
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Challenge: Asynchronous computations - Java Tutorial
From the course: Advanced Java: Threads and Concurrency
Challenge: Asynchronous computations
(lively music) - [Instructor] It's time for another challenge. Here you can practice what you learned about asynchronous programming, like Future and CompletableFuture. In this challenge, I want you to work on four simple coding tasks that are based on asynchronous computations. You are given the required code to work on the challenge. In the code, you can see two tasks in SumOfEvenTask and SumOfSqauresTask classes. They're implemented as two time-consuming tasks by implementing the callable interface. Just for your information, time-consuming tasks are simulated by using delays with the help of sleep method calls in code. There are four classes in which you should implement code for the four tasks. In task one, you should implement code to submit two asynchronous tasks to an executor service and obtain future objects for them. Once they are both done, call the get method against them. Analyze how long both tasks have taken to execute. In task two, create a CompletableFuture by…