两个远程对象是相关的,应该在一个操作中更新。如果您假设两个对象可以位于不同的系统上并且多个操作可以同时发生,那么您需要什么样的服务?
例如,您可以使用CompletableFuture
// create promises to get product
CompletableFuture<List<String>> product1 = CompletableFuture.completedFuture(callService1());
CompletableFuture<List<String>> product2 = CompletableFuture.completedFuture(callService2());
CompletableFuture<List<String>> product3 = CompletableFuture.completedFuture(callService3());
// collect promises just for convenience
List<CompletableFuture<List<String>>> allFutures = Arrays.asList(product1, product2, product3);
// wait until all cars will be obtained
CompletableFuture<List<String>> listCompletableFuture =
CompletableFuture.allOf(product1, product2, product3)
.thenApply(avoid -> allFutures //start to collect them
.stream()
.flatMap(f -> f.join().stream()) //get List from feature. Here these cars has been obtained, therefore non blocking
.collect(Collectors.toList())
);