如何限制使用的AsyncTask推出的线程数? [英] How to limit the number of threads launched using ASyncTask?

查看:107
本文介绍了如何限制使用的AsyncTask推出的线程数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与一些用户的Facebook好友列表中的列表视图,每一行示出了名称和朋友的图片。为了获得来自Facebook的图片我启动使用的AsyncTask,以下吉尔斯线程Debunne的文章多线程对性能

I've got a listview with the list of some user's facebook friends, with each row showing the name and the picture of the friend. To get the picture from Facebook I launch a thread using ASyncTask, following Gilles Debunne's post "Multithreading For Performance".

当我向下滚动列表,直到年底,推出可以是巨大的线程数,这使得一切都非常缓慢,直到所有的线程完成自己的任务。

When I scroll down the list until the end, the number of threads launched can be huge, which makes everything very slow until all threads finish their task.

如何限制线程数?

感谢

朱利安

推荐答案

现在,除非你愿意限制自己的API等级11(Android 3.0的)和更高,你不能限制由<$ C使用的线程数$ C>的AsyncTask 。 IIRC,它会使用多达20个线程的最大值。

Right now, unless you are willing to limit yourself to API Level 11 (Android 3.0) and higher, you cannot limit the number of threads used by AsyncTask. IIRC, it will use up to 20 threads maximum.

如果你想比少,您将需要创建自己的线程池机制和使用,而不是的AsyncTask 。或者,从克隆的AsyncTask 的code到自己的项目,并修改自己的线程池的特点。

If you want fewer than that, you will need to create your own thread pool mechanism and use that instead of AsyncTask. Or, clone the code from AsyncTask into your own project and modify the characteristics of its own thread pool.

这篇关于如何限制使用的AsyncTask推出的线程数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆