You get RejectedExecutionException
because the waiting queue of the thread pool is full and you try to post another task. You should propably start here to refactor/rethink your code, because the queue size seems to be 10 plus the active thread which should be sufficent in most circumstances. Its very likely that some of your task don't finish or are long runngin task and block the others or that you wildly post threads ;)
Asynctask has 2 build-in thread pools:
In SDK > 11 SERIAL_EXECUTOR is default. So you maybe try THREAD_POOL_EXECUTOR
, but beware, that this can only be used in SDK => 11 because executeOnExecutor
was a newer method. This will fix your immediate problem, but you mabye should reconsider if you need that many threads. Or use other methods e.g. services if you have many long running tasks.
Alternatively if you want your own ThreadPool you can create one with Executors: e.g. Executors.newCachedThreadPool() (among other static constructors).