问题
I've searched around for solutions to RejectedExecutionException using AsyncTaskLoader but none have worked. Most of them are for AsyncTask like https://github.com/commonsguy/cwac-task/blob/master/src/com/commonsware/cwac/task/AsyncTaskEx.java but AsyncTaskLoader is kind of different.
The first thing I tried was in onCreateLoader() doing this before returning a CursorLoader.
if (loaderCount >= 100)
{
cursorLoader.setUpdateThrottle(1000000000);
}
All that really does is stop the loaders after 100 which is not what I want. I tried toying around with different values but it seemed like a waste of time as it didn't solve the problem.
Then I found this: Submitting tasks to a thread-pool gives RejectedExecutionException but I'm not really sure how that answer helps this problem or how to use it with a asynctaskloader.
I also tried to create a ThreadPoolExecutor object to change the pool size but I'm not really sure how you can use that and asynctaskLoader at the same time. I'm not even sure if it would change anything.
I also tried to do Thread.sleep() but that just works on the UI thread I found out and does nothing for background threads I think.
I could do an app redesign for this specific case that I'm doing that throws the execution, but the loader count would only go down to 26 or 28. I heard that 10 is the max for certain Android versions so I'm pretty worried. Hopefully I don't have to resort to just doing my queries in the UI thread, since they run pretty fast already I think. It's just I can't do more than 128 queries apparently using a CursorLoader. How do I solve this problem? What should I do?
This is the Caused by: section of the log
Caused by: java.util.concurrent.RejectedExecutionException: Task android.support.v4.content.ModernAsyncTask$3@414f9bc0 rejected from java.util.concurrent.ThreadPoolExecutor@411d9600[Running, pool size = 128, active threads = 128, queued tasks = 10, completed tasks = 0]
来源:https://stackoverflow.com/questions/17138095/rejectedexecutionexception-128-active-threads-asynctaskloader