内部类完成后Java开始下一次循环迭代

所以我被困在一个非常基本的 Java 事情上。


即我有一个iteration需要在inner class完成后进入下一个循环。但是由于inner class需要很多时间并且variables可以访问的inner class必须是final它抛出我RejectedExecutionException。


java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3@290074 rejected from java.util.concurrent.ThreadPoolExecutor@d50b99d[Running, pool size = 17, active threads = 17, queued tasks = 128, completed tasks = 42]

这是引发异常的简化解决方案。


for (int i = 0; i < 10;i++) {


        String[] cmd = { "-i",  imageToBeFiltered.toString(), "-filter_complex", filters[loopCounter], imageWithFilter.toString()};


        ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {


            @Override

            public void onSuccess(String message) {

                super.onSuccess(message);


                //Continue loop only if it has reached onSuccess or onFailure


            }

            @Override

            public void onFailure(String message) {

                super.onFailure(message);

                //Continue loop only if it has reached onSuccess or onFailure

            }

        });

    }

}

当做正常时,fori-loop它并不总是等待所有terminal calls完成并继续。


富国沪深
浏览 147回答 1
1回答

森栏

你考虑过递归吗?void myMethod(int index) {&nbsp; &nbsp; String[] cmd = { "-i",&nbsp; imageToBeFiltered.toString(), "-filter_complex", filters[loopCounter], imageWithFilter.toString()};&nbsp; &nbsp; ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onSuccess(String message) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.onSuccess(message);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (index < 10) myMethod(index++);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onFailure(String message) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; super.onFailure(message);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (index < 10) myMethod(index++);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });}编辑:我猜这loopCounter应该是索引,在这种情况下,如果您使用此代码,您将需要更改它。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java