Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Jakarta Concurrency: Present and Future

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Wird geladen in …3
×

Hier ansehen

1 von 37 Anzeige

Jakarta Concurrency: Present and Future

Herunterladen, um offline zu lesen

Jakarta Concurrency is the successor of the Java EE Concurrency API. Jakarta Concurrency provides concurrency features aligned with Java SE that work in the Jakarta EE environment. For Jakarta EE 10 the team significantly upgraded Jakarta Concurrency. In this talk Steve Millidge, the lead of the Jakarta Concurrency project, will talk you through the new features in Jakarta EE 10, ideas for the future and how you can contribute to shape Jakarta Concurrency.

These slides were presented at the Community Day at the EclipseCon 2022 https://www.eclipsecon.org/2022/jakarta-ee-community-day

Read more about Jakarta Concurrency on our blog: https://blog.payara.fish/jakarta-concurrency-present-and-future

Find out more about Payara and Jakarta EE on https://www.payara.fish/solutions/jakarta-ee-and-the-payara-platform/

Jakarta Concurrency is the successor of the Java EE Concurrency API. Jakarta Concurrency provides concurrency features aligned with Java SE that work in the Jakarta EE environment. For Jakarta EE 10 the team significantly upgraded Jakarta Concurrency. In this talk Steve Millidge, the lead of the Jakarta Concurrency project, will talk you through the new features in Jakarta EE 10, ideas for the future and how you can contribute to shape Jakarta Concurrency.

These slides were presented at the Community Day at the EclipseCon 2022 https://www.eclipsecon.org/2022/jakarta-ee-community-day

Read more about Jakarta Concurrency on our blog: https://blog.payara.fish/jakarta-concurrency-present-and-future

Find out more about Payara and Jakarta EE on https://www.payara.fish/solutions/jakarta-ee-and-the-payara-platform/

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie Jakarta Concurrency: Present and Future (20)

Weitere von Payara (20)

Anzeige

Aktuellste (20)

Jakarta Concurrency: Present and Future

  1. 1. Jakarta Concurrency: Present and Future Steve Millidge
  2. 2. Agenda • Why do we need Jakarta Concurrency? • What are the main components? • What’s new in Jakarta EE 10? • Futures • Get Involved.
  3. 3. 3 Why do we need Jakarta Concurrency?
  4. 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. 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
  6. 6. What is an Application Server?
  7. 7. 9 What is the Use Case? Adding an Asynch Break in your application (Before JSR 236) Many older Java EE Applications use JMS just for this!
  8. 8. 10 What is the Use Case? Adding an Asynch Break in your application (Jakarta Concurrency) Much more lightweight than a JMS Broker!!!
  9. 9. Show me the Code (Simple Asynch Break – pre JakartaEE 10)
  10. 10. What is the Use Case? Running Tasks in Parallel (Jakarta Concurrency)
  11. 11. Show me the Code Parallel Tasks
  12. 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
  13. 13. 15 What are the Main Components?
  14. 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. 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. 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
  17. 17. 19 What’s new in Jakarta EE 10?
  18. 18. Jakarta EE 10 provides annotations for application scoped objects. @ManagedExecutorDefinition ( name="java:comp/env/concurrent/MyExecutor", context = "java:comp/env/concurrent/ContextService", maxAsync = 20, hungTaskThreshold = 5000 ) @ManagedScheduledExecutorDefinition ( name="java:comp/env/concurrent/MyExecutor", context = "java:comp/env/concurrent/ContextService", maxAsync = 20, hungTaskThreshold = 5000 ) Deployable Managed Objects
  19. 19. ● ContextServiceDefinition ● ManagedExecutorDefinition ● ManagedScheduledExecutorDefintion ● ManagedThreadFactoryDefinition Deployable Managed Objects
  20. 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. 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
  22. 22. Fork Join Pool Example
  23. 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. 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. 25. 27 Futures COPYRIGHT (C) 2019, ECLIPSE FOUNDATION, INC. | MADE AVAILABLE UNDER THE ECLIPSE PUBLIC LICENSE 2.0 (EPL-2.0) 27
  26. 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. 27. Currently Objects are tied to JNDI therefore need @Resource @ApplicationScoped public class CDIBean { @Inject ManagedExecutorService service; } @Inject Support for Managed Objects
  28. 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. 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. 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. 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
  32. 32. 34 Getting Involved COPYRIGHT (C) 2019, ECLIPSE FOUNDATION, INC. | MADE AVAILABLE UNDER THE ECLIPSE PUBLIC LICENSE 2.0 (EPL-2.0) 34
  33. 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...
  34. 34. Please visit us at: payara.fish/join-us
  35. 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. 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. 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

×