开发者

How can I return a Future object with Spring without writing concurrency logic?

How can I return a java.util.concurrent.Future object with a Receipt object and only use the @javax.ejb.Asynchronous annotation?

And do I need any extra configuration to let Spring handle ejb annotations?

I don't want to 开发者_开发技巧write any concurrency logic myself.

Here's my attempt that doesn't work:

@Asynchronous
public Future<Receipt> execute(Job job) {
    Receipt receipt = timeConsumingWork(job);
    return receipt;
}


As long as your configuration is correct, all you need to do is to return a new AsyncResult object with the receipt as input parameter.

@Asynchronous
public Future<Receipt> execute(Job job) {
    Receipt receipt = timeConsumingWork(job);
    return new AsyncResult<Receipt>(receipt);
}

Spring handles both @Async and @Asynchronous with the <task:annotation-driven /> element.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜