How many AsyncTasks i can run in an single process application

こ雲淡風輕ζ 提交于 2019-11-29 03:55:41
Computerish

How many AsyncTasks can you run at once?

In most versions of Android, the answer is 128.

Why will you generally see exactly 5 AsyncTask threads?

AsyncTask thread management is rather confusing, especially since it has changed a lot since the first Android release.

In newer Android versions, 5 threads are create by default, and the ThreadPoolExecutor will attempt to run the AsyncTasks on these 5 threads. If you create more than 5 AsyncTasks, it may either queue them or create new threads (but only up to 128).

Note that in earlier versions of Android, these limits were differently. I believe that, originally, there was only ever one thread created.

But all your images should load eventually...

To answer the other part of your question, unless you're loading a lot of images (where a lot means >128), all the images should load, although likely sequentially. If the first 5 load and the rest do not, that might indicate that your doInBackground() function is never finishing or there is something else wrong with the AsyncTask you are using.

Resources:

Here are some helpful resources for learning more about AsyncTask thread management:

AsyncTask threads never die

Android AsyncTask threads limits?

Is there a limit of AsyncTasks to be executed at the same time?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!