views:

394

answers:

1

I am fetching lots of thumbnails from a remote server and displaying them in a grid view, using AsyncTask. The problem is, my grid view displays 20 thumbnails at a time, so that creates 20 AsyncTasks and starts 20 executes, one per thumbnail.

I get RejectedExecution exception in my code. I recall reading somewhere that there is a limit to number of tasks that AsyncTask can have in its queue at a time, i might be hitting that. Was this bar lifted?

Is there a way to increase this limit? Is it safe to just ignore this exception?(by having an empty catch(RejectedException e){} block?)

I am running this code on Android 1.6 emulator and the API level in my code(minSDKVersion is 3). [EDIT: Added SDK and API level info]

+1  A: 

I recall reading somewhere that there is a limit to number of tasks that AsyncTask can have in its queue at a time, i might be hitting that. Was this bar lifted?

AsyncTask appears to presently support 10 threads and a work queue depth of 10. In theory, that would just support 20 items...if nothing else is using AsyncTask.

Is there a way to increase this limit?

Grab the source code, modify it, put it in your own package, and use that one. I did this with my AsyncTaskEx, though that is based on the Android 1.5 source.

Is it safe to just ignore this exception?

Your work will not be queued for execution. Whether that is "safe" is up to you. I am not aware of any other impacts on the AsyncTask infrastructure.

CommonsWare
Thanks Mark for your reply and also for sharing your code! BTW, as per Romain Guy's comment here: http://stackoverflow.com/questions/990948/simple-thread-management-java-android the limit seems to have been relaxed.
Samuh
Unfortunately, I can't confirm his statement. What I have above is from my examination of the source code (as found via Google Code Search). It could be I am misreading the code, though.
CommonsWare
I'm hitting the same issue. I would be perfectly happy to have my tasks executed in sequence instead of in parallel. Is there a way to do this? Or am I going back to implementing a work queue?
Edward Falk
@Edward Falk: As I wrote above, "Grab the source code, modify it, put it in your own package, and use that one." Just tweak the LinkedBlockingQueue settings to match your desired pattern.
CommonsWare