InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

New Java Concurrency Feature: Phasers

Posted by R.J. Lorimer on Jul 13, 2008

Sections
Development,
Architecture & Design
Topics
JCP Standards ,
Java ,
Performance & Scalability
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

Watch Thread Reply

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.