InfoQ

News

New Java Concurrency Feature: Phasers

Posted by R.J. Lorimer on Jul 13, 2008 09:41 PM

Community
Java
Topics
Performance & Scalability,
JCP Standards
Tags
Concurrency,
JCP
Doug Lea, the spec lead of the JSR 166 concurrency utilities, posted on the 166y concurrency-interest mailing list this week regarding a new feature being introduced into JSR-166y: Phasers.
The flexible barrier functionality that was previously restricted to ForkJoinTasks (in class forkjoin.TaskBarrier) is being redone as class Phaser (targeted for j.u.c, not j.u.c.forkjoin), that can be applied in all kinds of tasks.
The 'Phaser' concept and name was coined in this whitepaper by a team at Rice University. The name comes from the construct's phase-ordering and deadlock-avoidance properties. The whitepaper explains several details of the phaser concept. When comparing phasers to existing Java features, it is explained that similar functionality to the CyclicBarrier class is supported (introduced in Java 5), but phasers are inherently more flexible:
The [java.util.concurrent] CyclicBarrier class supports periodic barrier synchronization among a set of threads. Unlike Phasers, however, CyclicBarriers do not support the dynamic addition or removal of threads; nor do they support one-way synchronization or split-phase operation.
One of the main motivators for exploring additional barrier implementations was not just to have increased flexibility, but also to increase performance and scalability of the barrier synchronization concept:
Performance results obtained from a portable implementation of phasers on three different SMP platforms demonstrate that they can deliver superior performance to existing barrier implementations, in addition to the productivity benefits that result from their generality and safety properties.
As mentioned by Doug Lea, the implementation of Phaser for JSR-166y is being adapted from facilities in the existing fork/join framework implementation. The fork/join framework is something that InfoQ has covered before on multiple occasions, and is one of the central features in the upcoming 166y JSR - it is also the subject of a whitepaper by Doug Lea that describes the purpose and usage of the framework. The TaskBarrier class mentioned above was used by the fork/join framework to manage the boundaries between the various tasks, and merge their results; in other words: to join the tasks.

A draft Javadoc for the Phaser class in JSR-166y is available. Lea made it clear in his email to the interest list that this was still a draft:
Comments and suggestions are very welcome as always. The API is likely to change a bit as we scope out further uses, and also, hopefully, stumble upon some better method names.
It is currently expected that JSR-166y will be included as part of Java 7.

No comments

Reply

Exclusive Content

Typemock: Past, Present and Future

Eli Lopian of Typemock answers a few questions on Typemock origins and where Typemock is headed.

Agile in Practice: What Is Actually Going On Out There?

Scott Ambler talks about actual data resulting from surveys made during 2006-2008, showing how Agile is perceived and implemented within organizations.

Building Smart Windows Applications

From QCon 2008, Daniel Moth presents on using Visual Studio 2008 and .NET 3.5 to create compelling rich Windows applications.

Joshua Kerievsky about Industrial XP

Joshua Kerievsky, founder of Industrial Logic, talks about Industrial Extreme Programming which extends XP by including practices dealing with management, customers and developers.

Jeff Barr Discusses Amazon Web Services

Amazon Web Services (AWS) Evangelist Jeff Barr discusses SimpleDB, S3, EC2, SQS, cloud computing, how different Amazon services interact, origins of AWS, AWS globalization and the March AWS outage.

More Than Just Spin (Up) : Virtualization for the Enterprise and SaaS

Cloud services have helped bring virtualization to the forefront. Its full power however, also includes other benefits such as high availability, disaster recovery, and rapid provisioning.

Ruby Beyond Rails

John Lam talks about his path to dynamic languages, some of the problems of making IronRuby run fast, and how the DLR helps with implementing languages.

VMware Infrastructure 3 Book Excerpt and Author Interview

VMware Infrastructure 3: Advanced Technical Design Guide and Advanced Operations Guide provides a wealth of practical insights into setting up virtualization in todays corporate environments.