Antonyt:
All Asynctasks is controlled internally by a shared (static) Threadpoolexecutor and Alinkedblockingqueue. When you execute are on a asynctask, the'll execute it when it's ready some time in the future ThreadPoolExecutor .
The ' When AM I ready? ' behaviour of a threadpoolexecutor is controlled by II parameters, THE&NB Sp Core Pool size and the Maximum pool size . If there is less than core pool size threads currently active and a new job comes in, the executor would create a new thre AD and execute it immediately. If there was at least core pool size threads running, it would try to queue the job and wait until there was an idle thread Available (i.e. until another job is completed). If It is not possible to queue the job (the queue can has a max capacity), it would create a new thread (upto maximum pool Size threads) for the Steve to run in. Non-core Idle threads can eventually is decommissioned according to a keep-alive timeout parameter.
Before Android 1.6, the core pool size is 1 and the maximum pool size was 10. Since Android 1.6, the core pore size is 5, and the maximum pool size is 128. The size of the queue is ten in both cases. The Keep-alive timeout was ten seconds before 2.3, and 1 second since then.
With all of the "this", it now becomes clear why the would only AsyncTask appear to execute 5/6 of your tasks. The 6th task is being queued up until one of the other tasks complete. This was a very good reason why do you should don't use Asynctasks for long-running operations-it would prevent other Asynctask s from ever running.
For completeness, if you repeated your exercise with more than 6 tasks (e.g.), you'll see that more than 6 'll enter As the queue would become full and the doInBackground executor are pushed to create more worker threads. If you kept with the long-running task, you should see this 20/30 become active, with ten still in the queue.
Android will open a thread pool to specifically manage child thread startup issues, and when the thread pool is less than the maximum number of threads, it will be started, and when the thread Cheng, the other thread will wait until the current one is closed.
Asynctask-threads-limits question about Android: whether the thread Asynctask open has the limit