Jakarta Concurrency
3.1
3.0
2.0
1.0

This feature enables the creation of managed executors that allow applications to submit tasks to run concurrently, with thread context that is managed by the application server. It also enables the creation of managed thread factories to create threads that run with the thread context of the component that looks up the managed thread factory.

Enabling this feature

To enable the Jakarta Concurrency 3.1 feature, add the following element declaration into your server.xml file, inside the featureManager element:

<feature>concurrent-3.1</feature>

Examples

Virtual Threads

In Java 21 and later, you can configure managed executors to run tasks on virtual threads instead of platform threads. You can enable virtual thread support by setting the virtual attribute to true in the @ManagedExecutorDefinition, @ManagedScheduledExecutorDefinition, or @ManagedThreadFactory annotations. In the following example, a managed executor is defined to use virtual threads:

@ManagedExecutorDefinition(
    name = "java:module/concurrent/virtual-executor",
    virtual = true
)
public class MyServlet extends HttpServlet {

    @Resource(lookup = "java:module/concurrent/virtual-executor")
    ManagedExecutorService virtualManagedExecutor;

    public void virtualTask() {
        virtualManagedExecutor.submit(() -> {
            // This task runs on a virtual thread
        });
    };
}

Schedule Annotation

The @Schedule annotation enables scheduling of asynchronous methods. When an @Asynchronous method is invoked with a @Schedule, it runs on the specified schedule after the initial invocation.

Using a cron expression to define a schedule that becomes effective after the application invokes the counter() method:

@Asynchronous(runAt = @Schedule(cron = "*/30 * * * *"))
void counter() {
    // Runs every 30 minutes
}

Defines a schedule using an interval and automatically activates on application startup via CDI’s @Observes Startup:

@Asynchronous(runAt = @Schedule(daysOfWeek = DayOfWeek.FRIDAY, hours = 9))
void fridayMorning(@Observes Startup event) {
    // Runs every Friday at 9:00 AM
}

Standard API packages provided by this feature

  • jakarta.annotation

  • jakarta.annotation.security

  • jakarta.annotation.sql

  • jakarta.enterprise.concurrent

  • jakarta.enterprise.concurrent.spi

Supported Java versions

  • JavaSE-17.0

  • JavaSE-21.0

  • JavaSE-25.0

  • JavaSE-26.0

Developing a feature that depends on this feature

If you are developing a feature that depends on this feature, include the following item in the Subsystem-Content header in your feature manifest file.

io.openliberty.concurrent-3.1; type="osgi.subsystem.feature"