简体   繁体   English

CompletableFuture.runAsync未完成执行

[英]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 , CompletableFutureFuture接口的实现,您希望将像素异步渲染到画布上,但是您不等待将来完成其计算,

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.

相关问题 CompletableFuture.runAsync 吞咽异常 - CompletableFuture.runAsync Swallowing Exceptions 为什么不执行CompletableFuture.runAsync? - Why CompletableFuture.runAsync is not executed? CompletableFuture.runAsync 与 CompletableFuture 数组 - CompletableFuture.runAsync vs array of CompletableFuture CompletableFuture.runAsync 是否有任何线程限制 - Is there any thread limit on CompletableFuture.runAsync 具有非最终变量的CompletableFuture.runAsync(()-&gt;… - CompletableFuture.runAsync(() ->… with a non-final variable `thenRunAsync(...)`和`CompletableFuture.runAsync(()-&gt; {…}))是否完全相关? - Are `thenRunAsync(…)` and `CompletableFuture.runAsync(() -> { … });` related at all? Java CompletableFuture.runAsync重复发生……有潜在风险吗? - Java CompletableFuture.runAsync recurrsion … any potential risk? java8异步方法CompletableFuture.runAsync不运行 - java8 asynchronous method CompletableFuture.runAsync doesn't run 如果对 CompletableFuture.runAsync() 调用过多会发生什么? - What happens if you make too many calls to CompletableFuture.runAsync()? 为什么 CompletableFuture.runAsync() 不总是提交给 ForkJoinPool.commonPool()? - Why does CompletableFuture.runAsync() not always submit to ForkJoinPool.commonPool()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM