丢失了来自CompletableFuture.allOf

问题描述

问题是我必须一个一个地调用一个API,所以我使用下面的CompleableFunction

List<CompletableFuture<Void>> completableFutures = new ArrayList<>();
List<Bclass> listAll = new ArrayList<>();

for (SthClass e : result) {
  CompletableFuture<Void> future = CompletableFuture.supplyAsync(() -> fundInService.doRetryTransaction(retryTransactionRequestDto),threadConfiguration.getAsyncExecutor())
                            .thenAccept((result) -> {
                                Aclass a = new Aclass();

                                listAll.add(a);
                            });
  completableFutures.add(future);
}

CompletableFuture<Void> allFutures = CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0]));
allFutures.get();

我从allFutures中获得了listAll的随机大小

我不知道这段代码是Java的新功能

解决方法

使用// Create and show test image realimage img := RealImage( "Test Image 2D",4,512,512 ) img = abs( itheta*2*icol/(iwidth+1)* sin(iTheta*10) ) + 15*(irow<iheight/2 ? irow : iheight-irow )/iheight img = PoissonRandom(100*img) img.ShowImage() // Transform to Fourier Space compleximage img_FFT := FFT(img) // Create "Mask" or Filter in Fourier Space // This is where all the "adaptive" things have to happen to create // the correct mask. The below is just a dummy image mask := RealImage("Mask",512 ) mask = (iradius<iheight/3 && iradius>5 ) ? 1 : 0 mask = SQRT((icol-iwidth/2-100)**2+(irow-iheight/2-50)**2) < 25 ? 0 : mask mask = SQRT((icol-iwidth/2+100)**2+(irow-iheight/2+50)**2) < 25 ? 0 : mask mask.ShowImage() // Apply mask img_FFT *= mask img_FFT.SetName( "Masked FFT" ) img_FFT.ShowImage() // Transform back image img_filter := modulus(iFFT(img_FFT)) img_filter.SetName( img.GetName() + " Filtered" ) img_filter.ShowImage() // Just arrange EGUPerformActionWithAllShownImages("arrange") 代替synchronizedList,因为ArrayList不是线程安全的

ArrayList

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...