如何限制使用的AsyncTask推出的线程数?线程、AsyncTask

由网友(醉后余欢。)分享简介:我有与一些用户的Facebook好友列表中的列表视图,每一行示出了名称和朋友的图片。为了获得来自Facebook的图片我启动使用的AsyncTask,以下吉尔斯线程Debunne的文章多线程对性能。I've got a listview with the list of some user's facebook fr...

我有与一些用户的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的)和更高,你不能限制由的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.

阅读全文

相关推荐

最新文章