簡體   English   中英

循環中的Java異步rest調用

[英]Java async rest call in a loop

我有一個返回客戶名稱的休息服務,並且我想進行異步調用以檢索客戶列表的名稱。

因此,我有一個客戶列表,目前正在迭代該列表並一個接一個地撥打電話:

 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;

有什么方法可以異步方式進行此調用,以便可以並行執行嗎?

感謝和問候

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM