In the previous posts about the java.util.concurrent framework, I introduced what for me is the core of the package and what you will use the most on real-world applications.
Going further with the topic, it’s worth to know the new fork/join framework introduced in Java 7. The pros and cons of this framework over the usage of thread pools or regular thread/runnable development has been subject of a lot of debate, but I think it is still a nice tool to have in your arsenal.
I’ll use a more classic approach to show you the basic structure of the fork/join framework and code a version of the Quicksort algorithm using it.
My goal here is to introduce you to the tools provided by the fork/join structure in Java 7, this is not a discussion about the best Quicksort implementation. If you want to delve into implementing the best Quicksort possible I recommend you check out this great post about it.
The fork/join framework provides a very straightforward and intuitive structure to implement recursive and divide and conquer problems that can be solved concurrently. You start with the big problem and break it down in smaller work units until each work unit can be solved directly.
The implementation of your problem solver must be a subclass of ForkJoinTask, and you will most likely implement a subclass of it’s children RecursiveAction or RecursiveTask; RecursiveAction represents a recursive problem solver, capable of solving a small enough problem directly or breaking it down into smaller work units; RecursiveTask is similar, but it also has the capability of returning a result for each work unit executed.
Read full article from An Introduction to the Fork / Join Framework | Javalobby
No comments:
Post a Comment