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 {

    
    @Resource
    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 {

    @Inject
    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.

Comments:

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