我的Async实现无法正常运行,尽管看来我已正确完成了所有操作。
我正在从EndPoint类中调用异步方法。
请在下面查看我的代码,并协助我解决问题。
我的EndPoint类如下:
@Endpoint
public class EndpointDummy {
private static final String TARGET_NAMESPACE = "http://www.abc.xyz.com/GetAcctInfo";
@Autowired
private DummyService service;
@PayloadRoot(localPart = "GetAcctInfoRq", namespace = TARGET_NAMESPACE)
public @ResponsePayload GetAcctInfoRs handleRequest(@RequestPayload GetAcctInfoRq request, MessageContext messageContext) throws JAXBException, TransformerException {
/*****************************************************************
* Call the handler function
* This handler function is asynchronous
*****************************************************************/
service.handleRequest();
/*****************************************************************
* Send response back
*****************************************************************/
SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse();
SoapHeader respheader = soapResponse.getSoapHeader();
MsgHdrRs msgHdrRs = new MsgHdrRs();
JAXBContext jaxbContext = JAXBContext.newInstance(MsgHdrRs.class);
jaxbContext.createMarshaller().marshal(msgHdrRs, respheader.getResult());
GetAcctInfoRs response = new GetAcctInfoRs();
return response;
}
}
如上所述,我的EndPoint类调用DummyService方法handleRequest。
虚拟服务类使用@Service进行注解,方法handRequest使用@Async进行注解,如下所示:
@Service
public class DummyService {
private Logger logger = Logger.getLogger(DummyService.class);
@Async("taskExecutorServiceImpl")
public void handleRequest() {
logger.info("DummyService: 1");
try {
Thread.sleep(20000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
logger.info("DummyService: 2");
}
}
我还定义了如下的配置类:
@Configuration
@EnableAsync
public class ThreadConfig {
@Bean(name = "taskExecutorServiceImpl")
public ThreadPoolTaskExecutor specificTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.initialize();
return executor;
}
}
请帮助我解决问题。我是Spring框架的新手,希望能对此有所帮助。
谢谢
答案 0 :(得分:0)
问题已解决,与上面的代码无关。 问题出在配置文件中,与上面的正确代码无关。