问题
My technical stack includes
- Tomcat 8.5.47 (plain, not EE)
- Weld 2.4.8.Final (as a reference implementation of CDI 1.2)
To be able to use ManagedExecutorService and manage threads more wisely and in a safer manner, I would like to include this dependency
- org.glassfis:javax.enterprise.concurrent (as a reference implementation of JSR 236 [Concurrency Utilities])
I tried to inject the bean in different ways and into differently-scoped beans (view-, session-, application-based).
@Inject
private javax.enterprise.concurrent.ManagedExecutorService service;
@Resource
private javax.enterprise.concurrent.ManagedExecutorService service;
@Resource(lookup="java:comp/DefaultManagedExecutorService")
private javax.enterprise.concurrent.ManagedExecutorService service;
Nothing seems to work and the exception goes
java.lang.RuntimeException: Error looking up java:comp/env/.../ManagedExecutorService in JNDI javax.naming.NameNotFoundException: Name [.../ManagedExecutorService] is not bound in this Context.
It might be due to improper bean registration. Because I found none. I scanned the whole classpath and couldn't find anything that defines ManagedExecutorService
or any of its implementations somewhere.
I tried to register it by myself in the context.xml
to no avail. I used this TomEE tutorial (naively) assuming that configuration for my non-EE Tomcat would be the same.
<Resource name="ManagedExecutorService"
type="javax.enterprise.concurrent.ManagedExecutorService" />
<Resource id="ManagedExecutorService"
type="javax.enterprise.concurrent.ManagedExecutorService" />
Apparently, it's not.
My questions are
Is it possible to set up Concurrency Utilities on a non-EE server, Tomcat 8.5 in particular?
If so, what am I missing here?
I can't switch to any JavaEE application server.
I can't upgrade the listed dependencies.
Related:
Java EE specification and multi threading
Is it safe to manually start a new thread in Java EE?
Why am I getting a WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped exception?
来源:https://stackoverflow.com/questions/58846495/how-to-make-concurrency-utilities-jsr-236-work-in-plain-non-ee-tomcat-8