So I got stuck on a pretty basic Java thing.
Namely I have an iteration
that needs to go to a next loop after the inner class
has finished. But since the inner class
takes a lot of time and the variables
that can be accessed in inner class
must be final
it throws me 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]
Here is the simplified solution that threw the exception.
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
}
});
}
}
When doing the normal fori-loop
it does not always wait for all of the terminal calls
to finish and just goes on.