java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution - android

Fatal Exception: java.util.concurrent.RejectedExecutionException
Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask#52a169d rejected
from g.j.d.p.r.v0.c$a#649b174[Terminated, pool size = 0, active threads = 0, queued tasks =
0, completed tasks = 4668]
This is an issue I came across from the crashlytics of my project. Help me figure out the solution here.

Related

RejectedExecutionException has occured in coroutines

the rejectedexecutionexception occurs on app but does not point out from which action/thread/class its coming from. I have used nothing to manually shutdown threads or anything. But this is coming from coroutines
Fatal Exception: java.util.concurrent.RejectedExecutionException
Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask#eeb06f2 rejected from java.util.concurrent.ScheduledThreadPoolExecutor#75be143[Shutting down, pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]
java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution (ThreadPoolExecutor.java:2086)
java.util.concurrent.ScheduledThreadPoolExecutor.schedule (ScheduledThreadPoolExecutor.java:562)
a.a.b.a.b.d.c.a (c.java:4)
a.a.b.a.b.d.a.a (a.java:21)
a.a.b.a.b.b.a (b.java:5)
a.a.b.a.b.e.a.a (a.java:19)
a.a.b.a.c.e.a$c.invokeSuspend (a.java:6)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (BaseContinuationImpl.java:33)
a.a.a.o0.run (o0.java:28)
a.a.a.c2.a$a.run (a.java:590)

java.util.concurrent.RejectedExecutionException with limited Asynctask

I am getting
java.util.concurrent.RejectedExecutionException: Task
android.os.AsyncTask$3#672f695 rejected from
java.util.concurrent.ThreadPoolExecutor#25293aa[Running, pool size =
17, active threads = 17, queued tasks = 128, completed tasks = 165].
How to resolve issue? Even i have just started 6-7 AsyncTask.
Let me know in which situations i can get above error.

Need help understanding 'RejectedExecutionExemption'

I am running some async tasks and 1 of my users is crashing with a RejectedExecutionExemption:
Stack Trace
stackTrace: java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3#5e2675f rejected from java.util.concurrent.ThreadPoolExecutor#f5f25ac[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 240]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2014)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:794)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1340)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:607)
The Line causing the exception
new SetDownloadStatusTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Two Part question here really..
I'd like like some help understanding the first line of the exception:
ThreadPoolExecutor#f5f25ac[Running, pool size = 9, active threads = 9, queued tasks = 128, completed tasks = 240]
pool size vs. active threads vs quad tasks.. I assume I am executing too many tasks, but am unsure how to determine this really for those three variables. If someone could break that down for me, Id appreciate it.
If this is the case that I am running out of threads, should I increase the amount allowed and if so how, or is there a better solution.
Custom AsyncTask
private class SetDownloadStatusTask extends AsyncTask<Void, Void, DownloadStatus> {
#Override
protected DownloadStatus doInBackground(Void... params) {
return bookDownloadManager.status(product);
}
#Override
public void onPostExecute(DownloadStatus downloadStatus) {
updateMenuForDownloadStatus(downloadStatus);
}
}
I assume I am executing too many tasks
Correct.
If someone could break that down for me, Id appreciate it
AsyncTask.THREAD_POOL_EXECUTOR, on a quad-core CPU, will support nine parallel threads (pool size = 9). That is backed by a LinkedBlockingQueue of maximum length 128. And, you have requested your 138th simultaneous task, so we are out of threads (active threads = 9) and the queue is full (queued tasks = 128).
should I increase the amount allowed and if so how, or is there a better solution
You should be asking yourself "why in the name of all that is holy am I trying to download 138 things at once?".
If there is a legitimate need for that, use your own custom Executor, rather than THREAD_POOL_EXECUTOR. If there is not a legitimate need for 138+ simultaneous downloads — and, frankly, that number seems insane — then change your code to avoid doing that, such as cancelling tasks that you no longer need.

Android Fatal signal 6 (SIGABRT) from asyncTask

I have a working android game which occasionally force closes on slow devices with the error
Fatal signal 6 (SIGABRT), code -6 in tid 14620 (AsyncTask #1)
Research indicated to me that this was due to delaying the execution of the UI thread, so, i bundled up the peace of code (about 200 lines of bitmap and region creation) into an AsyncTask (doInBackground method) and i now run that task from the UI thread using task.execute.
The problem is, this has in no way stopped the error. If anything the app force closes more frequently during the execution of that code despite the fact it should be running in an asyncTask.
In the interest of being thorough, the error is triggered during the execution of this part of the code (extract from the 200ish block):
Back.outerPath.setFillType(Path.FillType.EVEN_ODD);
Region tempRegion = new Region(PathBoundsRectangle);
Back.outerRegion.setPath(Back.outerPath, tempRegion);
Back.innerRegion.setPath(Back.innerPath, tempRegion);
Back.fastRegion.setPath(Back.speedPath, tempRegion);
Back.slowRegion.setPath(Back.slowPath, tempRegion);
Back.outerRegion.op(Back.innerRegion, Region.Op.XOR);
Matrix scaleMatrix = new Matrix();
RectF rectF = new RectF();
Back.innerPath.computeBounds(rectF, true);
scaleMatrix.setScale(1.1f, 1.1f,rectF.centerX(),rectF.centerY());
Back.innerPath.transform(scaleMatrix);
Back.outerPath.computeBounds(rectF, true);
scaleMatrix.setScale(0.9f, 0.9f,rectF.centerX(),rectF.centerY());
Back.outerPath.transform(scaleMatrix);
Back.outerSideBandRegion.setPath(Back.outerPath, tempRegion);
Back.outerSideBandRegion.op(Back.outerRegion, Region.Op.XOR);
Back.innerSideBandRegion.setPath(Back.innerPath, tempRegion);
Back.innerSideBandRegion.op(Back.innerRegion, Region.Op.XOR);
Any ideas? Is it possible the code is still running on the UI thread? Can this error be due to something else?
EDIT: It turns out the error is coming from the Region.op.XOR manipulations. Anyone see how this could cause a Fatal Error?
I have also observed this when calling Region.Op.INTERSECT on regions derived from extremely long and complex paths.
The solution that works for me is to maintain a record of all the path waypoints, and then to build a list of smaller paths onto which the Region.Op.INTERSECT operation gets executed individually.

RejectedExecutionException from AsyncTask, but haven't hit limits

My Android app has to deal with arriving messages which frequently come in bunches (especially during periods of flaky connectivity). I handle these incoming messages in AsyncTasks so that I don't interfere with the UI thread. If too many messages come in at once, I get a RejectedExecutionException. My error stack looks like this:
10-22 14:44:49.398: E/AndroidRuntime(17834): Caused by: java.util.concurrent.RejectedExecutionException: Task android.os.AsyncTask$3#414cbe68 rejected from java.util.concurrent.ThreadPoolExecutor#412716b8[Running, pool size = 128, active threads = 22, queued tasks = 0, completed tasks = 1323]
10-22 14:44:49.398: E/AndroidRuntime(17834): at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1967)
10-22 14:44:49.398: E/AndroidRuntime(17834): at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:782)
10-22 14:44:49.398: E/AndroidRuntime(17834): at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1303)
10-22 14:44:49.398: E/AndroidRuntime(17834): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:564)
I'm running the tasks with task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) so that incoming messages are processed in parallel.
What is confusing about this, and different from related StackOverflow questions that I can find (e.g. here and here), is that the number of active threads and queued tasks don't seem to be bumping up against the limits (which seem to be 128 and 10, respectively). See the stacktrace:
ThreadPoolExecutor#412716b8[Running, pool size = 128, active threads = 22, queued tasks = 0, completed tasks = 1323]
Why would I be getting this error message?
Why would I be getting this error message?
If the ThreadPoolExecutor is still running, you would get this error message only if you have exceeded the number of tasks that can be queued by the ThreadPoolExecutor. The only time the RejectedExecutionException is thrown is by the ThreadPoolExecutor.AbortPolicy which is the default RejectedExecutionHandler.
To quote from the javadocs:
If a request cannot be queued, a new thread is created unless this would exceed maximumPoolSize, in which case, the task will be rejected.
There is a maximum number of tasks. See this question/answer here: Is there a limit of AsyncTasks to be executed at the same time?
Here's a link for the sourcecode for AsyncTask.
private static final int CORE_POOL_SIZE = 5;
private static final int MAXIMUM_POOL_SIZE = 128;
private static final BlockingQueue<Runnable> sWorkQueue =
new LinkedBlockingQueue<Runnable>(10);
private static final ThreadPoolExecutor sExecutor =
new ThreadPoolExecutor(CORE_POOL_SIZE, MAXIMUM_POOL_SIZE,
KEEP_ALIVE, TimeUnit.SECONDS, sWorkQueue, sThreadFactory);
So it looks like it starts at 5 threads, has a queue of 10. Once the queue is full it can start up to 128 threads. So it looks like you have exceeded 138 simultaneous requests.
ThreadPoolExecutor#412716b8[Running, pool size = 128, active threads = 22, queued tasks = 0, completed tasks = 1323]
Trying to catch the ThreadPoolExecutor the exact moment that it runs out of space is going to be very hard and it will quickly turn into a heisenbug in that the more you look at the ThreadPoolExecutor numbers, the more you are going to affect the synchronization of that class and therefore you might make the bug go away.
In your case, by the time you get to log the exception with the details about the TPE, the condition must have passed.
This exception also occur if your Executor call shutdown method and after that you give new Task (Runnable) for execution.
Like
mThreadPoolExecutor.shutdown();
...
...
...
mThreadPoolExecutor.execute(new Runnable(){...});

Categories

Resources