Asynctask-threads-limits question about Android: whether the thread Asynctask open has the limit

Source: Internet
Author: User

Http://stackoverflow.com/questions/9654148/android-asynctask-threads-limits

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.