Search code examples
asynchronouspojojava-ee-7

Can I invoke POJO method asynchronously in java ee 7 without using EJB?


I would like to invoke a method that send an email. This method has void return type so I do not need to use the Future interface for handling the result. All the Java ee 7 documentation cover this topic if you use session beans. Is there any way to use the async approach for a normal method invocation?


Solution

  • you could use java.util.concurrent.Future and java.util.concurrent.CompletableFutureto call your method asynchronously.

    Future<Integer> futureInteger = CompletableFuture.supplyAsync(() -> getInteger(parameter));