Java Concurrency - java.util.concurrent

> Procedural Languages > Java > Java - Concurrency (Parallel Work)

1 - About

Since Java 1.5, java.util.concurrent

  • java.util.concurrent.locks. Interfaces and classes providing a framework for locking and waiting for conditions that is distinct from built-in synchronization and monitors.
  • java.util.concurrent.atomic: A small toolkit of classes that support lock-free thread-safe programming on single variables.
Advertising

3 - Executors

3.1 - (Interfaces|Model)

3.1.1 - Executor

See Executor

3.1.2 - Future (Results and Execution cancelation)

A Future:

  • returns the results of a function, allows determination of whether execution has completed,
  • and provides a means to cancel execution.

A RunnableFuture is a Future that possesses a run method that upon (during ?) execution, sets its results.

3.2 - Implementations

3.2.1 - ThreadPool

Object

Factory

The Executor Service are normally created and configured using Executors factory methods. The Executors class provides:

  • factory methods for the most common kinds and configurations of Executors,
  • as well as a few utility methods for using them.

Futures

  • FutureTask: base implementation of Future, with methods to start and cancel a computation, query to see if the computation is complete, and retrieve the result of the computation. A FutureTask can be used to wrap a Callable or Runnable object.

Completion Service

  • ExecutorCompletionService uses a supplied Executor to execute tasks. This class arranges that submitted tasks are, upon completion, placed on a queue accessible using take. It assists in coordinating the processing of groups of asynchronous tasks.
Advertising

3.2.2 - ForkJoinTask

  • ForkJoinPool: Class ForkJoinPool provides an Executor primarily designed for processing instances of ForkJoinTask and its subclasses. These classes employ a work-stealing scheduler that attains high throughput for tasks conforming to restrictions that often hold in computation-intensive parallel processing.

4 - Documentation / Reference