[英]CompletableFuture.runAsync not finishing execution
我正在嘗試使用CompletableFuture在JavaFX畫布上寫入大量像素,盡管沒有引發異常,但我的方法似乎並未完成其任務。
我是異步編程的新手,不確定應該從哪里開始,但是我認為這可能可以從收集到的信息中解決。
我正在嘗試使用:
CompletableFuture.runAsync(() -> {
mandelbrot.increaseScale();
drawMandelbrot();
});
致電:
private void drawMandelbrot() {
//RENDER
gc.clearRect(0,0,UISpecs.CANVAS_SIZE.getValue(),UISpecs.CANVAS_SIZE.getValue()); // clears canvas of any previously set pixels
gc.setFill(Color.BLACK); // set canvas background to be black
gc.fillRect(0,0,UISpecs.CANVAS_SIZE.getValue(),UISpecs.CANVAS_SIZE.getValue()); // set canvas background
for(double a = -2; a <= 2; a+=.001) {
for(double b = -2; b <= 2; b+=.001) {
c = new Complex(a,b);
col = pickColor(doIterations(c));
p.setColor(mandelbrot.getX(a), mandelbrot.getY(b), col);
}
}
} // drawMandelbrot()
我的complex(a,b)和pickColor(i)方法非常瑣碎,它們都非常小而簡單。 因此,我相信嵌套循環是造成我麻煩的原因。
任何指導或意見都將不勝感激。
CompletableFuture
是Future
接口的實現,您希望將像素異步渲染到畫布上,但是您不等待將來完成其計算,
CompletableFuture<Void> completableFuture =CompletableFuture.runAsync(() -> {
mandelbrot.increaseScale();
drawMandelbrot();
});
completableFuture.get();
CompletableFuture.get()的文檔明確指出:等待異步計算完成,然后返回
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.