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

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

And do I need extra tweaking for Spring to handle ejb annotations?

I do not want to write any concurrency logic.

Here my attempt does not work:

 @Asynchronous public Future<Receipt> execute(Job job) { Receipt receipt = timeConsumingWork(job); return receipt; } 
+4
source share
1 answer

If your configuration is correct, all you have to do is return a new AsyncResult object with a receipt as an input parameter.

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

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

+6
source

Source: https://habr.com/ru/post/1310781/


All Articles