我可以在 java ee 7 中异步调用 POJO 方法而不使用 EJB 吗?
Can I invoke POJO method asynchronously in java ee 7 without using EJB?
我想调用一个发送电子邮件的方法。此方法具有 void return 类型,因此我不需要使用 Future 接口来处理结果。如果您使用会话 bean,所有 Java ee 7 文档都涵盖了这个主题。
有什么方法可以使用异步方法进行普通方法调用吗?
您可以使用 java.util.concurrent.Future
和 java.util.concurrent.CompletableFuture
异步调用您的方法。
Future<Integer> futureInteger = CompletableFuture.supplyAsync(() -> getInteger(parameter));
我想调用一个发送电子邮件的方法。此方法具有 void return 类型,因此我不需要使用 Future 接口来处理结果。如果您使用会话 bean,所有 Java ee 7 文档都涵盖了这个主题。 有什么方法可以使用异步方法进行普通方法调用吗?
您可以使用 java.util.concurrent.Future
和 java.util.concurrent.CompletableFuture
异步调用您的方法。
Future<Integer> futureInteger = CompletableFuture.supplyAsync(() -> getInteger(parameter));