[concurrency-interest] CountedCompleters

Doug Lea dl at cs.oswego.edu
Mon Apr 9 10:16:01 EDT 2012

After sitting on multiple variations for months, I committed
CountedCompleter, a completion-based flavor of ForkJoinTask.

As mentioned a few times over the past year, the main motivation
is to better support tasks that perform IO or other base
actions that may (or may not) take a lot of time to execute.
As is the case with JDK7 async IO and other completion-based
frameworks, the most common path to efficiency is for such tasks
to arrange continuation actions that occur upon their completion.
The main twist for CountedCompleters is that continuations
might be dependent on multiple actions, not just one. (Or in
other words, the continuations must be preceded by a specialized,
"bottom-up" form of join.)

The CountedCompleter abstract class provides a minimal basis
for these kinds of tasks. While some of the mechanics are
reminiscent of other FJ-like frameworks such as Intel TBB,
CountedCompleters are designed to fit smoothly with other
kinds of ForkJoinTasks (like RecursiveActions), and so still
allow people to use the more pleasant Future-style conventions
rather than count-based bottom-up joining unless they need them.
At the same time, the CountedCompleter class exposes enough
mechanics to allow all sorts of tweaks that people can use
to improve performance.
In particular, in addition to usually being the best way to deal
with IO etc bound tasks, CountedCompleters sometimes fare better
than RecursiveActions in programs that entail lots of garbage
collection because GC can have similar impact on task variability.

Even though targeted for JDK8, versions of CountedCompleter
appear in the jsr166y and main repositories, not jsr166e. This is
because they require a non-public hook into modified ForkJoinTask
exception handling mechanics in order to properly propagate
exceptional completions. For sources, docs, and jar files, see
the usual links at http://gee.cs.oswego.edu/dl/concurrency-interest/index.html

The API docs include more details and some examples:

I also added a few (with more to come) test/demo programs that illustrate
other usages. See CCBoxedLongSort and CCJacobi in

Please try these out. As always, comments and suggestions
(hopefully based on usage experience) would be welcome.


More information about the Concurrency-interest mailing list