Ayant:rejoindre CompletableFuture vs méthode synchrone
String getData(String key){
// Slow operation
}
CompletableFuture<String> getDataAsync(String key){
return CompletableFuture.supplyAsync(() -> getData(key));
}
Quelle est la différence entre ce qui suit?
a)
keyStream.map(key -> getData(key));
b)
keyStream.map(key -> getDataAsync(key).join());
est-il un avantage à utiliser async dans ce cas?
S'il vous plaît expliquer votre question un peu plus. –
Il n'y a pas de différence: 'join()' se bloque jusqu'à ce qu'un résultat soit disponible. – ck1