Equivalent of Task Parallel Library in Java

Java has the java.util.concurrent package, and there's also the fork/join framework. Fork/join is scheduled for inclusion in Java 7, but can be downloaded now and used with Java 6.

A good book for getting to grips with concurrency in Java is Java Concurrency in Practice, by Brian Goetz and others.


Habanero-Java library (HJ-lib) is the new library implementation of Habanero-Java (HJ), a pedagogic parallel programming model being developed at Rice University. HJ-lib is capable of expressing many different forms of parallel patterns including data parallelism, pipeline parallelism, stream parallelism, loop parallelism, and divide-and-conquer parallelism.

HJ-lib integrates a wide range of parallel programming constructs (e.g., async tasks, futures, data-driven tasks, forall, barriers, phasers, transactions, actors) in a single programming model that enables unique combinations of these constructs (e.g., nested combinations of task and actor parallelism).

HJ-lib is built using lambda expressions and can run on any Java 8 JVM. Older JVMs can be targeted by relying on external bytecode transformations tools for compatibility. The HJ runtime is responsible for orchestrating the creation, execution, and termination of HJ tasks, and features both work-sharing and work-stealing schedulers.

HJ-lib is also an attractive tool for educators with numerous educational resources available from the sophomore-level COMP 322 course offered at Rice University. These resources can also be used to learn about the library API. Javadoc for the API is also available.

Here is a simple HelloWorld version:

import static edu.rice.hj.Module1.*;

public class HelloWorld {

    public static void main(final String[] args) {

        launchHabaneroApp(() -> {

            finish(() -> {
                async(() -> System.out.println("Hello"));
                async(() -> System.out.println("World"));
                async(() -> System.out.println("in"));
                async(() -> System.out.println("HJ-lib"));
            });

        });
    }
}

Further examples for the various parallel constructs are available from the COMP 322 course website.