I have a bunch of methods using Phaser
(with always 1 party) and I could replace each method by using CompletableFuture
instead. The result would be the same. Are there any hidden benefits when using CompletableFuture
?
For example:
version 1 with CompletableFuture:
void queryVersion1() {
var future = new CompletableFuture<Void>();
asyncCall(future);
future.join();
}
void asyncCall(CompletableFuture<Void> future){
...
future.complete(null);
}
version 2 with Phaser:
void queryVersion2() {
var phaser = new Phaser(1);
asyncCall(phaser);
phaser.awaitAdvance(0);
}
void asyncCall(Phaser phaser){
...
phaser.arriveAndDeregister();
}
Which one should I prefer and why? Which one performs better in terms of memory/thread pool/etc.