Jakarta Concurrency provides APIs for concurrency and asynchronous programming in Java EE and Jakarta EE applications. It allows adding asynchronous breaks and running tasks in parallel or periodically. New features in Jakarta EE 10 include deployable managed executor services and scheduled executor services. Future plans include better integration with CDI contexts and aligning asynchronous servlets and JAX-RS with Concurrency. Developers are encouraged to get involved in the open source Eclipse project.
4. 6
What is Jakarta Concurrency
New name for JSR236: Concurrency Utilities for Java EE
• Introduced in Java EE 7
• No change in Java EE 8
• No change in Jakarta EE 8
• Namespace change in Jakarta EE 9
• New Features Jakarta EE 10
New Maven coordinates in Jakarta EE 8/9/10
<dependency>
<groupId>jakarta.enterprise.concurrent</groupId>
<artifactId>jakarta.enterprise.concurrent-api</artifactId>
<version>1.1.2 (8) 2.0 (9.x) 3.0.2 (10.0)</version>
</dependency>
Steve Millidge
5. 7
Goal
• Utilize existing applicable Java EE platform services. Provide a simple yet
flexible API for application component providers to design applications
using concurrency design principles.
• Allow Java SE developers a simple migration path to the Java EE
platform by providing consistency between the Java SE and Java EE
platforms.
• Allow application component providers to easily add concurrency to
existing Java EE applications.
• Support simple (common) and advanced concurrency patterns without
sacrificing usability
12. Running Periodic Tasks
(Jakarta Concurrency)
What is the Use Case?
Before Java EE Concurrency this
could only be achieved using EJB
Timers
Tasks can also be started at Application Deploy
Trigger enables programmatic scheduling
14. Managed Executor Services
Managed
Executor
Service
Jakarta EE
Executor
Service
Java SE
Managed
Scheduled
Executor
Service
Scheduled
Executor
Service
Jakarta EE specifies
a default instance of
each.
Additional instances
can be configured for
specific needs.
Managed Task
Listener can track
Task execution
Trigger interface can
provide business logic
on when to schedule
a task
15. Managed Thread Factory
Managed
Thread
Factory
Jakarta EE
Thread
Factory
Java SE
Used where you need a non-
Jakarta EE component to
create threads that can be
utilised with Jakarta EE.
or
You need a managed thread
to do something asynch.
16. Used when you need an object to run on a non managed thread using a Jakarta EE
Context.
Key for maintaining Security Context that can be propagated to other threads
One example is a JMX Notification Listener
Context Service
20. Like the EJB Asnchronous annotation but can be used with CDI beans.
Methods must return CompletableFuture, CompletionStage or void
@ApplicationScoped
public class AsynchBean {
@Asynchronous(executor=" java:comp/env/concurrent/MyExecutor")
public CompletableFuture<Double> asynchMethod() {
Double total;
…
return Asynchronous.Result.complete(total);
}
}
Specifying the Executor service will enable fine grained concurrency management when combined
with deployable executor services.
New @Asynchronous annotation
21. Support ForkJoinPool in a standard way and allow creation of Managed Fork Join Pools
public interface ManagedThreadFactory extends ThreadFactory,
ForkJionPool.ForkJoinWorkerThreadFactory
Support CompletableFuture on Executor
CompletableFuture<Void> runAsync(Runnable runnable);
<U> CompletableFuture<U> supplyAsync(Supplier<U> supplier);
Date Time Support on Triggers
public interface ZonedTrigger extends Trigger {
public ZonedDateTime getNextRunTime(LastExecution lastExecutionInfo,
ZonedDateTime taskScheduledTime);
…
Catch up with Java
23. Easier creation of Contextual aware components
public <R> Supplier<R> contextualSupplier(Supplier<R> supplier);
public <T, R> Function<T, R> contextualFunction(Function<T, R>
function);
public <T, U> BiConsumer<T, U> contextualConsumer(BiConsumer<T, U>
consumer);
public <R> Callable<R> contextualCallable(Callable<R> callable);
public Runnable contextualRunnable(Runnable runnable);
public <T> CompletionStage<T> withContextCapture(CompletionStage<T>
stage);
public <T> CompletableFuture<T>
withContextCapture(CompletableFuture<T> stage);
Context Service Upgrade to Java SE 8+
24. CronTrigger class - Implementation
● Concrete Trigger Implementation for Convenience
public CronTrigger(final String cron, final ZoneId zone)
Use Expressions
trigger = new CronTrigger("0 7 * SEP-MAY MON-FRI",
ZoneId.of("America/New_York"));
Use Fluent API
trigger = new CronTrigger(ZoneId.of("America/Los_Angeles"))
.months(Month.DECEMBER)
.daysOfMonth(24)
.hours(16, 18);
25. 27
Futures
COPYRIGHT (C) 2019, ECLIPSE FOUNDATION, INC. | MADE AVAILABLE UNDER THE ECLIPSE PUBLIC LICENSE 2.0 (EPL-2.0) 27
26. Like the EJB Timer annotation but for other components e.g. CDI Beans (non-persistent)
@ApplicationScoped
public class ScheduledBean {
@Schedule(executor="MyExecutor", minute="*/5")
public void fiveMinuteRule() {
}
}
Supports cron like commands (c.f. EJB).
Some comments are that this can be done in plain Java utilising CronTrigger and would
need to change the schedule
@Schedule Annotation · Issue #98 · jakartaee/concurrency (github.com)
New @Schedule Annotation
27. Currently Objects are tied to JNDI therefore need @Resource
@ApplicationScoped
public class CDIBean {
@Inject ManagedExecutorService service;
}
@Inject Support for Managed Objects
28. Provides locking semantics for CDI Beans – especially useful for ApplicationScoped
@ApplicationScoped
public class CDIBean {
@Lock(LockType.READ) doReadMany(){};
@Lock(LockType.WRITE) doOneWriter();
}
Semantics would be similar to EJB Locks
@Lock Annotation
Lock Annotation · Issue #135 · jakartaee/concurrency (github.com)
@Lock(LockType.READ)
29. Limits through Semaphore the number of threads that can execute a method or all
methods concurrently.
@ApplicationScoped
public class CDIBean {
@MaxConcurrency(2) maxTwoThreadsMethod(){};
@MaxConcurrency(10) maxUseofAPI();
}
Thread Isolation can be currently handled through Asynchronous with a
ManagedExecutor with maxConcurrency specified.
@MaxConcurrency Annotation
MaxConcurrency annotation · Issue #136 · jakartaee/concurrency (github.com)
@Lock(LockType.READ)
30. Possible Future Platform Alignment
● Specify more how Concurrency interacts with Jakarta Context and Dependency
Injection Contexts
● Enable propagation of Transactions across threads
● Reimplement Jakarta Enterprise Beans Asynchronous on Concurrency
○ Use new Concurrency Asynchronous annotation
○ Alternate allow MES to be specified
● Reimplement Jakarta Enterprise Beans Timers on Concurrency
○ Use new Schedule annotation
○ Alternate allow MES to be specified
● Align Asynch Servlets and JAX-RS onto Concurrency
○ Provide logical executor name
31. ● Support Flow API
○ https://github.com/jakartaee/concurrency/issues/257
○ No work done as yet
● Make usable in Core Profile
○ Remove requirements for JNDI and EJBs in TCK
Others
33. Get Involved!
• Eclipse Project
• https://projects.eclipse.org/
projects/ee4j.cu
• Mailing List
• https://accounts.eclipse.org
/mailing-list/cu-dev
• Code
• https://github.com/jakartaee/concurrency
• Raise Issues for New Features.
• Review what is their for EE10
• Eclipse Compatible Implementation
(used in GlassFish and Payara)
• https://github.com/eclipse-ee4j/concurrency-ri
v
THIS IS CODE FIRST, OPEN SOURCE DEVELOPMENT...
35. Payara is always on the hunt for the
best people to work with - Someone
that makes a difference, cares for
quality, and is really good at their job
Learn more:
https://payara.fish/careers
We’re Hiring
36. • Payara is a proud 2021 Queen's Award for
Enterprise recipient for International Trade.
• Overseas sales grew by 107% in the last
three years and the percentage exported
grew from 33% to 75%
Winner of The
Queens Award for
Enterprise
37. Join our Global Meetup Group to find out more about our
future events and get involved with our community
Learn more:
https://www.meetup.com/payara-global-meetup/
Payara Global Meetup