gpt4 book ai didi

Java 循环中的异步休息调用

转载 作者:行者123 更新时间:2023-12-02 12:04:21 25 4
gpt4 key购买 nike

我有一个返回客户姓名的休息服务,我想进行异步调用来检索客户列表的姓名。

所以我有一个客户列表,目前我正在迭代该列表并逐一进行调用:

 public List<Participant> retrieveParticipantsFullName(List<Participant> participantList) throws GeneralException {

for (Participant participant : participantList) {
String fullRetrievePartFullURL = retrieveParticipantsFullNameUrl+participant.getCustomerType()+"/"+participant.getCustomerID();
ResponseEntity<RetrieveCustomerNameResponse> resultResp ;

resultResp = restTemplate.getForEntity(fullRetrievePartFullURL,
RetrieveCustomerNameResponse.class);
participant.setCustomerMiddlename(resultResp.getBody().getCustomerNameOut().getCustomerMiddlename());
}

return participantList;

有没有办法以异步方式进行此调用,以便可以并行执行?

谢谢问候

最佳答案

是的,您需要使用AsyncRestTemplate,而不是使用RestTemplate,它返回ListenableFuture

关于Java 循环中的异步休息调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47013676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com