我正在将@RestController与返回DeferredResult的方法一起使用。
我有一份可以完成的未来清单,每个阶段都有如下所示的不同阶段
for (Integer unit : getIds()) {
futureList.add(CompletableFuture.completedFuture(unit)
.thenApply(id -> CompletableFuture
.completedFuture(service.get1(id))
.thenCombineAsync(CompletableFuture.completedFuture(b), (a, df1) ->
CompletableFuture.completedFuture(service.validate(Optional.ofNullable(a),c,
b, dealerCode))
.thenApplyAsync(status -> CompletableFuture.completedFuture(b))
.thenCombineAsync(CompletableFuture.completedFuture(a), (b1, a1) ->
service.mapToTrans(Optional.ofNullable(a), b, c))
.handle((response, exception) -> {
if(exception == null) {
return response;
}
else {
handler.handleException(exception, results);
return null;
}
})
.thenApplyAsync(t -> service.submitRequest(Optional.ofNullable(a), c))
.thenApplyAsync((t) -> service.saveTransaction(Optional.ofNullable(t)))
.thenAccept(result1 -> results.add(result1))
)
.handle((response, exception) -> handleStage(response, exception, results))
)
.handle((response, exception) -> handleStage(response, exception, results))
);
}
我将在DeferredResult中设置结果,如下所示
futureList.forEach(cf -> {
CompletableFuture.allOf(cf).join();
});
deferredResult.setResult(ResponseEntity.ok().body(results));
})
但是我的回答是“结果”数组列表中的项目数量减少了。从日志中可以看到,所有期货都已成功执行。请让我知道问题是什么