问题描述
问题是我必须一个一个地调用一个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