[英]CompletableFuture.runAsync not finishing execution
I'm attempting to use CompletableFuture to write a large number of pixels on a JavaFX canvas, and my method does not seem to be completing its task despite no exceptions being thrown. 我正在尝试使用CompletableFuture在JavaFX画布上写入大量像素,尽管没有引发异常,但我的方法似乎并未完成其任务。
I'm new to asynchronous programming and am not sure where I should begin, but I thought this might work from what info I've gathered. 我是异步编程的新手,不确定应该从哪里开始,但是我认为这可能可以从收集到的信息中解决。
I'm attempting to use: 我正在尝试使用:
CompletableFuture.runAsync(() -> {
mandelbrot.increaseScale();
drawMandelbrot();
});
to call: 致电:
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()
My complex(a,b) and pickColor(i) methods are quite trivial, both do very small and simple operations. 我的complex(a,b)和pickColor(i)方法非常琐碎,它们都非常小而简单。 So I believe my nested loops are what is causing my trouble.
因此,我相信嵌套循环是造成我麻烦的原因。
Any guidance or input is greatly appreciated. 任何指导或意见都将不胜感激。
CompletableFuture
is an implementation of the Future
interface and you want your pixels to be rendered onto the canvas asynchronously but you are not waiting for the future to complete its computation , CompletableFuture
是Future
接口的实现,您希望将像素异步渲染到画布上,但是您不等待将来完成其计算,
CompletableFuture<Void> completableFuture =CompletableFuture.runAsync(() -> {
mandelbrot.increaseScale();
drawMandelbrot();
});
completableFuture.get();
The documentation for CompletableFuture.get() puts it clearly : Waits for the async computation to finish and then returns CompletableFuture.get()的文档明确指出:等待异步计算完成,然后返回
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.