'u engelleyebilir Bazı bloglarda (ör. I can't emphasize this enough: thenAccept()/thenRun() methods do not block) CompletableFuture.thenAccept
gerçekten engellenebilir. pause
yöntem çağrısı thenAccept
engellemek neden olacaktır uncommenting aşağıdaki kodu düşünün:CompletableFuture.thenAccept gerçekten de
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
log.trace("return 42");
return "42";
});
//pause(1000); //uncommenting this will cause blocking of thenAccept
future.thenAccept((dbl -> {
log.trace("blocking");
pause(500);
log.debug("Result: " + dbl);
}));
log.trace("end");
pause(1000);
aşağıda belirtilen bloke olmayacağından emin olabilir miyiz? supplyAsync
hemen çalışırsa thenAccept
'un engellenebileceğini anladım, değil mi?
CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> {
return "42";
}).thenAccept((dbl -> {
pause(500);
log.debug("Result: " + dbl);
}));