Tag: 并发完成

什么是等待可完成的未来线程完成的推荐方法

我正在使用CompletableFuture ,如下面的代码所示。 但关于我应该等到所有可运行完成的方式,我找到了两种方法,我不知道它们之间的区别,哪一种是最佳实践? 它们如下: 代码 : this.growSeedFutureList = CompletableFuture.runAsync(new GrowSeedSERun(this.saliencyMat, this.seedXY, this.seedVal), this.growSeedExecutor); this.growSeedFutureList = CompletableFuture.runAsync(new GrowSeedNWRun(this.saliencyMat, this.seedXY, this.seedVal), this.growSeedExecutor); this.growSeedFutureList = CompletableFuture.runAsync(new GrowSeedNERun(this.saliencyMat, this.seedXY, this.seedVal), this.growSeedExecutor); this.growSeedFutureList = CompletableFuture.runAsync(new GrowSeedSWRun(this.saliencyMat, this.seedXY, this.seedVal), this.growSeedExecutor); 第一种等待所有runnables完成的方法 : this.growSeedExecutor.shutdown(); this.growSeedExecutor.awaitTermination(1, TimeUnit.DAYS); 等待所有runnables完成的第二种方法 : CompletableFuture.allOf(this.growSeedFutureList).join(); 请让我知道推荐哪一个。