RejectedExecutionException 128 Active Threads AsyncTaskLoader
Asked Answered
H

0

3

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]
Hiltan answered 16/6, 2013 at 21:53 Comment(4)
Why would you ever need to do more than 128 simultaneous queries?Demetrius
I'm just running queries sequentially and checking if stuff is null, not necessarily outputting everything from 128 queries. I have a lot of data to check.Hiltan
But the 128-thread-limit on AsyncTask is on simultaneous operations. The only way you should get a RejectedExecutionException is if you are doing 138 queries at once, tying up all 128 threads and filling the 10-item work queue.Demetrius
I'm having the same issue. I suspect that I have a leak somewhere, so that tasks are not finishing.Noach

© 2022 - 2024 — McMap. All rights reserved.