From the course: Advanced Java: Threads and Concurrency
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Solution: Multiples calculator - Java Tutorial
From the course: Advanced Java: Threads and Concurrency
Solution: Multiples calculator
(techno music) - [Instructor] Now I'll walk you through my solution to this challenge step by step. I've extended the MultiplesCalculator class from RecursiveTask, as this task is supposed to not only calculate but also return the number of multiples. The type we'll be returning from it is integer, so the type parameter is integer. From line 16 to 27, the compute method is overridden to implement how the task should be executed based on the threshold value. If the size of the number list is less than or equal to the threshold, I do the computation directly or sequentially by calling the computeDirectly method. Let's go into it. This is where we have the core logic for finding multiples. Let's go back. If not, the problem is too large, which means the computation should be done recursively by dividing the fork joint task into two parts, and if required, further dividing or forking them into smaller subtasks by calling invokeAll that is in line 25. By calling join in line 27 on the…
Contents
-
-
-
-
-
-
(Locked)
Thread execution and the fork/join framework4m 11s
-
(Locked)
Worker threads and work stealing3m 28s
-
(Locked)
The core classes of the fork/join framework4m 50s
-
(Locked)
Using the fork/join framework6m 36s
-
(Locked)
Challenge: Multiples calculator2m 15s
-
(Locked)
Solution: Multiples calculator3m 57s
-
(Locked)
-
-
-
-