我正在尝试学习如何在野外11上使用Managed Executor服务,但是当我部署我的应用程序时,我收到以下错误:
10:28:34,185 ERROR [org.jboss.as.controller.management-operation](控制器启动线程)WFLYCTL0013:操作("部署")失败 - 地址:([(&#34 ;部署" =>" crowbar-server.war")]) - 失败描述:{
"WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.module.crowbar-server.crowbar-server.env.jboss.ee.concurrency.executor.default"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.crowbar-server.crowbar-server.env.\"com.ticomgeo.crowbar.server.ejb.ManagedExecutorExample\".mes is missing [jboss.naming.context.java.module.crowbar-server.crowbar-server.env.jboss.ee.concurrency.executor.default]"]
}
如果这是一个愚蠢的问题我提前道歉,但我对wildfly和JEE来说是全新的。
执行程序在standalone.xml中定义。 (我不得不删除尖括号或不显示,不确定如何转义XML)
subsystem xmlns="urn:jboss:domain:ee:4.0"
spec-descriptor-property-replacement>false</spec-descriptor-property-replacement
concurrent
context-services
context-service name="default" jndi-name="java:jboss/ee/concurrency/context/default" use-transaction-setup-provider="true"/
/context-services
managed-thread-factories
managed-thread-factory name="default" jndi-name="java:jboss/ee/concurrency/factory/default" context-service="default"/
/managed-thread-factories
managed-executor-services
managed-executor-service
name="default"
jndi-name="java:jboss/ee/concurrency/executor/default"
context-service="default"
hung-task-threshold="60000"
keepalive-time="5000"/>
/managed-executor-services
managed-scheduled-executor-services
managed-scheduled-executor-service name="default" jndi-name="java:jboss/ee/concurrency/scheduler/default" context-service="default" hung-task-threshold="60000" keepalive-time="3000"/
/managed-scheduled-executor-services
/concurrent
引用它的代码非常简单
package com.ticomgeo.crowbar.server.ejb;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.enterprise.concurrent.ManagedExecutorService;
@Singleton(name = "ManagedExecutorExample")
public class ManagedExecutorExample {
@Resource(lookup = "jboss/ee/concurrency/executor/default")
private ManagedExecutorService mes;
public void testMe(int secsToSleep){
mes.submit(new TestClass());
System.out.println("Submitted test class");
}
private class TestClass implements Runnable{
public void run(){
System.out.println("Running runable");
try {
Thread.sleep(10000);
}catch(Exception e){
}
System.out.println("Done Sleeping");
}
}
答案 0 :(得分:2)
请尝试使用完整的JNDI名称:
@Resource(lookup = "java:jboss/ee/concurrency/executor/default")
private ManagedExecutorService mes;
或者只是将其保留以获取默认资源:
@Resource
private ManagedExecutorService mes;