Java EJB @Asynchronous循环 - 在继续之前如何知道所有调用何时完成?
ejb 中有此代码
for (PayrollEntry pe : payroll.getEntries()) {
recalculatePayrollEntry(pe);
}
CalculateTotals(payroll);
我在调用此异步方法的
@Asynchronous
public void recalculatePayrollEntry(PayrollEntry pe) {
// Calculate Payroll Entry;
pe.setEarningsEntries(newEarnings);
}
在调用 CalcuateTotals 之前等待所有这些重新计算执行的最佳方法是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要将异步方法设置为
void
,而是返回 Future(代表异步计算)。启动作业,收集所有 future,然后等待它们完成:Instead of having your async method as
void
, return a Future (which represent an asynchronous calculation). Start up the jobs, collect all the futures, and then await their completion:我相信您可以让您的方法返回
AsyncResult
是一个
Future
。该方法的返回类型应为Future
收集列表中的所有 future,然后对每个调用
.get()
。I believe you can have your method return an
AsyncResult
which is aFuture
. The return type of the method should beFuture
Collect all futures in a list, and then call
.get()
on each.