From the course: Advanced Java: Threads and Concurrency

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Using the fork/join framework

Using the fork/join framework - Java Tutorial

From the course: Advanced Java: Threads and Concurrency

Using the fork/join framework

- [Instructor] Now I'm ready to show you how to use the core classes of the fork/join framework. The sum list action class here is a subclass of recursive action, which represents a fork/join task. The action is calculating the sum of a list of numbers. Let's say the list of numbers declared here in line five would have 10 numbers. This isn't, of course, a large computational task, but let's just try to grasp the concept using this example. I'm jumping to line 13, where we override the compute method. You can see that this method doesn't return anything, as recursive action represents a non-value returning task. The implementation here is the steps that you saw in the sorter code in an earlier video. Back in line six, I've defined a threshold value and initialized it to five in this case. Using this value, we can determine if the problem is small enough to be solved directly or sequentially. So in line 14, I check if the list size is less than or equal to the threshold value, and if…

Contents