JEP 266: More Concurrency Updates
Owner | Doug Lea |
Type | Feature |
Scope | SE |
Status | Closed / Delivered |
Release | 9 |
Component | core-libs / java.util.concurrent |
Discussion | core dash libs dash dev at openjdk dot java dot net |
Effort | S |
Duration | S |
Relates to | JEP 193: Variable Handles |
Reviewed by | Chris Hegarty, Martin Buchholz, Paul Sandoz |
Endorsed by | Brian Goetz |
Created | 2015/08/04 11:01 |
Updated | 2017/04/24 23:02 |
Issue | 8132960 |
Summary
An interoperable publish-subscribe framework, enhancements to the
CompletableFuture
API, and various other improvements.
Motivation
The continual evolution of uses of concurrency and parallelism in applications requires continual evolution in library support.
Description
-
Interfaces supporting the Reactive Streams publish-subscribe framework, nested within the new class
Flow
.Publisher
s produce items consumed by one or moreSubscriber
s, each managed by aSubscription
. Communication relies on a simple form of flow control (methodSubscription.request
, for communicating back pressure) that can be used to avoid resource management problems that may otherwise occur in "push" based systems. A utility classSubmissionPublisher
is provided that developers can use to create custom components.
These (very small) interfaces correspond to those defined with broad participation (from the Reactive Streams initiative) and support interoperability across a number of async systems running on JVMs. Nesting the interfaces within a class is a conservative policy allowing their use across various short-term and long-term possibilities. There are no plans to provide network- or I/O-basedjava.util.concurrent
components for distributed messaging, but it is possible that future JDK releases will include such APIs in other packages. -
Enhancements to the
CompletableFuture
API- Time-based enhancements are added that enable a future to complete with
a value or exceptionally after a certain duration, see methods
orTimeout
andcompleteTimeout
. In addition, a complementaryExecutor
returned by the static methods nameddelayedExecutor
allow a task to execute after a certain duration. This may be combined withExecutor
receiving methods onCompletableFuture
to support operations with time-delays. - Subclass enhancements are added making it easier to extend from
CompletableFuture
, such as to provide a subclass that supports an alternative default executor.
- Time-based enhancements are added that enable a future to complete with
a value or exceptionally after a certain duration, see methods
-
Numerous implementation improvements accumulated since JDK 8; many of them are small, but some include Javadoc spec rewordings.
Testing
The continuing set of JSR 166 EG members provide functionality, TCK, and performance tests for all components.
Risks and Assumptions
Care will be taken to ensure any small but required differences in code between the JDK 9 repository and the 166 repository are retained.