Reputation: 37484
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.
How can I limit the number of threads?
Thanks
Julien
Upvotes: 2
Views: 4316
Reputation: 1007399
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.
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.
Upvotes: 3
Reputation: 8942
You could use a ThreadPoolExecutor to limit the number of threads in the pool used for the tasks.
Upvotes: 0