Skip to content

Latest commit

 

History

History
54 lines (37 loc) · 4.4 KB

concurrencyprovider.asciidoc

File metadata and controls

54 lines (37 loc) · 4.4 KB

Concurrency Provider

A MicroProfile Concurrency implementation provides an implementation of the org.eclipse.microprofile.concurrent.spi.ConcurrencyProvider interface via either of the following mechanisms:

  • By manually registering the implementation via the static register(ConcurrencyProvider) method. This register returns a ConcurrencyProviderRegistration instance which can be used to unregister.

  • Alternately, via the ServiceLoader, by including a file of the following name and location: META-INF/services/org.eclipse.microprofile.concurrent.spi.ConcurrencyProvider. The content of the aforementioned file must a single line specifying the fully qualified name of the ConcurrencyProvider implementation that is provided within the JAR file.

The ConcurrencyProvider implementation has one main purpose, which is to supply and maintain instances of ConcurrencyManager per class loader. This is done via the getConcurrencyManager(ClassLoader) method.

In the case where the ConcurrencyProvider is fully integrated with the container, all other methods of ConcurrencyProvider are optional, with their default implementations being sufficient.

In the case where the ConcurrencyProvider implementation is distinct from the container, several other methods are made available to allow the container to build new instances of ConcurrencyManager (via getConcurrencyManagerBuilder), register these instances with the ConcurrencyProvider per class loader (registerConcurrencyManager), and unregister these instances when the class loader is no longer valid (releaseConcurrencyManager).

Concurrency Manager

ConcurrencyManager’s purpose is to provide builders for `ManagedExecutor and ThreadContext. The builders create instances of ManagedExecutor and ThreadContext where thread context management is based on the ThreadContextProvider’s that are accessible to the `ServiceLoader from the class loader that is associated with the ConcurrencyManager instance.

Concurrency Manager Builder

The builder for ConcurrencyManager is optional if the ConcurrencyProvider is inseparable from the container, in which case there is no need to provide an implementation.

This builder enables the container to create customized instances of ConcurrencyManager for a particular class loader. The container can choose to have thread context providers loaded from the class loader (addDiscoveredThreadContextProviders) or manually supply its own (withThreadContextProviders). Similarly, the container can choose to have extensions loaded from the class loader (addDiscoveredConcurrencyManagerExtensions) or provide its own (withConcurrencyManagerExtensions). The container is responsible for managing registration and unregistration of all ConcurrencyManager instances that it builds.

Concurrency Manager Extension

ConcurrencyManagerExtension is an optional plugin point that allows you to receive notification upon creation of each ConcurrencyManager. This serves as a convenient invocation point for enabling system wide context propagator hooks. After creating each ConcurrencyManager, the MicroProfile Concurrency implementation queries the ServiceLoader for implementations of org.eclipse.microprofile.concurrent.spi.ConcurrencyManagerExtension and invokes the setup method of each.

To register a ConcurrencyManagerExtension, a JAR file that is accessible from the class loader associated with the ConcurrencyManager must include a file of the following name and location,

META-INF/services/org.eclipse.microprofile.concurrent.spi.ConcurrencyManagerExtension

The content of the aforementioned file must be one or more lines, each specifying the fully qualified name of a ConcurrencyManagerExtension implementation that is provided within the JAR file.