From Jakarta EE ManagedExecutorService to MicroProfile ManagedExecutor

In Java EE / Jakarta EE environments a ManagedExecutorService instance is injectable via the @Resource annotation:

import javax.enterprise.concurrent.ManagedExecutorService;
public class EventSource {

    ManagedExecutorService threadPool;

[code from: Java EE 8: Sending asynchronous CDI 2.0 events with ManagedExecutorService]

In pure MicroProfile environments these API is not available but can be replaced with ManagedExecutor from MicroProfile Context Propagation:

import org.eclipse.microprofile.context.ManagedExecutor;
public class EventSource {

    ManagedExecutor executor;

Both injected instances are inheriting from ExecutorService. Migration from javax.enterprise.concurrent.ManagedExecutorService to org.eclipse.microprofile.context.ManagedExecutor should be matter of replacing @Resource with @Inject, renaming the injected classes and fixing the imports.


Post a Comment:
  • HTML Syntax: NOT allowed
...the last 150 posts
...the last 10 comments