Understanding the Java 7 Fork/Join Framework

An incisive and timely article by Julien Ponge, an Associate Professor in computer science at INSA de Lyon, titled “Fork and Join: Java Can Excel at Painless Parallel Programming, Too!” offers a detailed exploration of the new Java 7 fork/join framework. It begins with an explanation of low-level mechanisms involved in Java concurrent programming, then explores the rich primitives of the java.util.concurrent packages, and presents fork/join tasks plus example usage of the new APIs.

From the article itself:

“To illustrate the usage of the new fork/join framework, let us take a simple example in which we will count the occurrences of a word in a set of documents. First and foremost, fork/join tasks should operate as “pure” in-memory algorithms in which no I/O operations come into play. Also, communication between tasks through shared state should be avoided as much as possible, because that implies that locking might have to be performed. Ideally, tasks communicate only when one task forks another or when one task joins another.”

Read the complete article.

Comments:

Julien Ponge's fork/join example is nice. But suppose you want a list of 10 files with the most occurrences of the word, say as a sorted map from the number of occurrences to a file with that many. To avoid a global map, each node of the tree would have such a map and the join operation would combine the children's maps into a new map. But it seems more natural to have the threads read from and write to a global map. Could this be done using fork/join? say with one of the maps from the concurrent package?

Posted by guest on July 13, 2011 at 01:48 PM PDT #

Julien Ponge's fork/join example is nice. But suppose you want a list of 10 files with the most occurrences of the word, say as a sorted map from the number of occurrences to a file with that many. To avoid a global map, each node of the tree would have such a map and the join operation would combine the children's maps into a new map. But it seems more natural to have the threads read from and write to a global map. Could this be done using fork/join? say with one of the maps from the concurrent package?

Posted by guest on July 13, 2011 at 01:49 PM PDT #

Dear guest,

In this case you would opt for RecursiveAction rather than RecursiveTask. A shared collection is indeed better in some cases, like say, a huge array that you would like to sort.

Cheers

Posted by Julien Ponge on July 17, 2011 at 07:06 PM PDT #

Fork Join framework is best way to get most out of multiple processors available on today's modern and expensive servers. It can also be used to implement Map reduce pattern. Here is another way of using fork join framework in Java http://javarevisited.blogspot.tw/2011/09/fork-join-task-java7-tutorial.html

Posted by guest on September 26, 2012 at 02:48 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Insider News from the Java Team at Oracle!

duke
javeone logo
Links


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
5
6
7
12
13
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today