我的技术栈包括
-
雄猫 8.5.47 https://tomcat.apache.org/download-80.cgi(简单,非 EE)
-
焊接 2.4.8.最终 https://mvnrepository.com/artifact/org.jboss.weld.servlet/weld-servlet/2.4.8.Final(作为 CDI 1.2 的参考实现)
为了能够使用ManagedExecutorService https://docs.oracle.com/javaee/7/api/javax/enterprise/concurrent/ManagedExecutorService.html并以更明智、更安全的方式管理线程,我想包含此依赖项
-
org.glassfis:javax.enterprise.concurrent https://mvnrepository.com/artifact/org.glassfish/javax.enterprise.concurrent(作为参考实现JSR 236 [并发实用程序] https://jcp.org/en/jsr/detail?id=236)
我尝试以不同的方式将 bean 注入不同范围的 bean(基于视图、会话、应用程序)。
@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;
似乎没有任何作用,异常消失了
java.lang.RuntimeException:
Error looking up java:comp/env/.../ManagedExecutorService in JNDI
javax.naming.NameNotFoundException:
Name [.../ManagedExecutorService] is not bound in this Context.
这可能是由于 Bean 注册不当造成的。因为我没有找到。我扫描了整个类路径,但找不到任何定义的内容ManagedExecutorService
或其任何实现。
我尝试自己在context.xml
无济于事。我用了这个 TomEE 教程 https://tomee.apache.org/admin/configuration/resources.html(天真地)假设我的非 EE Tomcat 的配置是相同的。
<Resource name="ManagedExecutorService"
type="javax.enterprise.concurrent.ManagedExecutorService" />
<Resource id="ManagedExecutorService"
type="javax.enterprise.concurrent.ManagedExecutorService" />
显然,事实并非如此。
我的问题是
是否可以在非 EE 服务器(尤其是 Tomcat 8.5)上设置并发实用程序?
如果是这样,我在这里缺少什么?
我无法切换到任何 JavaEE 应用程序服务器。
我无法升级列出的依赖项。
Related:
Java EE 规范和多线程 https://stackoverflow.com/questions/3212255/java-ee-specification-and-multi-threading/19404307#19404307
在 Java EE 中手动启动新线程安全吗? https://stackoverflow.com/questions/6149919/is-it-safe-to-manually-start-a-new-thread-in-java-ee
为什么我会收到 WELD-001303: No active contexts forscope type javax.enterprise.context.RequestScoped 异常? https://stackoverflow.com/questions/46529534/why-am-i-getting-a-weld-001303-no-active-contexts-for-scope-type-javax-enterpri