Java 5 brought the basic concurrency support beyond Threads into Java: Futures + Executors. Those are very powerful concepts, but the resulting code is complex to maintain. Java 7 builds on the existing java.util.concurrent foundation by providing the 'fork-join' framework to Java (JSR166).
The concept behind the fork-join framework is "divide and conquer": a job is recursively split in halves, until a manageable size for the sub-jobs is found. The correct size for the chunks is typically determined by the number of cores (=Runtime.availableProcessors()). Another key concept is "work stealing": if one thread finishes its job early, it 'steals' work from other 'double-ended queues' (Deque) of other threads. That way all cores can remain busy while limitting congestion for the queue.
Java 7 java.util.concurrent.forkjoin:
- basic fork join classes: RecursiveAction, AsyncAction, CyclicAction ...
- higher abstraction: ParallelArray offers parallel functions out of the box: filter, map, replace, aggregate ... I like the declarative style use for this class: it chains declarations before firing the action: students.withFilter(isSenior).withMapping(selectGpa).summary();
Definitively an interesting step for Java, although once you enter a multi-threaded environment, you loose many safety guarantees from Java and you as a developer has to ensure that concurrency doesn't break your app. The growing number of cores puts parallel programming research in the spotlight, with the renewed interest in functional languages like haskell, erlang and Scala for example.
References:- (very small) intro http://www.devoxx.com/display/JV08/From+Concurrent+to+Parallel
- jsr-166: http://www.infoq.com/news/2008/03/fork_join
- research paper: http://gee.cs.oswego.edu/dl/papers/fj.pdf
- IBM: http://www.ibm.com/developerworks/java/library/j-jtp11137.html
- IBM: http://www.ibm.com/developerworks/java/library/j-jtp03048.html
No comments:
Post a Comment