所以我被困在一个非常基本的 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完成并继续。
1 回答
森栏
TA贡献1810条经验 获得超5个赞
你考虑过递归吗?
void myMethod(int index) {
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);
if (index < 10) myMethod(index++);
}
@Override
public void onFailure(String message) {
super.onFailure(message);
if (index < 10) myMethod(index++);
}
});
}
编辑:
我猜这loopCounter应该是索引,在这种情况下,如果您使用此代码,您将需要更改它。
添加回答
举报
0/150
提交
取消