【发布时间】:2016-06-17 03:30:33
【问题描述】:
我有一个对象集合。我必须在这个返回 Future 的对象集合上调用一个方法。现在我在 Future 上使用 get() 以便它使操作同步。如何将其转换为异步?
for (Summary summary : summaries) {
acmResponseFuture(summary.getClassification()));
String classification = summary.getClassification();
// this is a call which return Future and which is a sync call now
AcmResponse acmResponse = acmResponseFuture(classification).get();
if (acmResponse != null && acmResponse.getAcmInfo() != null) {
summary.setAcm(mapper.readValue(acmResponse.getAcmInfo().getAcm(), Object.class));
}
summary.setDataType(DATA_TYPE);
summary.setApplication(NAME);
summary.setId(summary.getEntityId());
summary.setApiRef(federatorConfig.getqApiRefUrl() + summary.getEntityId());
}
【问题讨论】:
-
为什么它是一个未来?
-
它是一个我们无法控制的外部 API。通常我们只需要传递一个 Record 给它,但是在这种情况下我们可以传递一个集合
标签: java twitter-finagle