| | |
| | | import java.net.URL; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | if (stockList.size() > 0){ |
| | | stockListVOS.addAll(Objects.requireNonNull(StockApi.getStockReailTimes(stockList))); |
| | | } |
| | | for (int i = 0; i <stockListVOS.size() ; i++) { |
| | | stockListVOS.get(i).setNowPrice(iPriceServices.getNowPrice(stockListVOS.get(i).getCode(),stockType).toString()); |
| | | List<CompletableFuture<Void>> futures = new ArrayList<>(); |
| | | |
| | | // Use CompletableFuture to perform asynchronous processing for each stockListVO |
| | | for (StockListVO stockListVO : stockListVOS) { |
| | | CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { |
| | | stockListVO.setNowPrice(iPriceServices.getNowPrice(stockListVO.getCode(), stockType).toString()); |
| | | }); |
| | | futures.add(future); |
| | | } |
| | | |
| | | // Wait for all futures to complete |
| | | CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); |
| | | RPageInfo pageInfo = new RPageInfo(); |
| | | pageInfo.setList(stockListVOS); |
| | | pageInfo.setStockType(stockType); |