Why do you start 21 threads? Just start one task and put your loop inside doInBackground().
On Tue, Jun 2, 2009 at 2:51 AM, MIMRAN D <david.mim...@gmail.com> wrote: > > Hi all, > > I am struck with an interesting problem. > > I have a listview with 30 items which contains an image (from a web > server) and a text. > So, when I load pictures, I start a new thread with the AsyncTask > class to do not block the UI thread. > But, if I have more than 20 threads at the same times, I have a > RejectedExecutionException from the ThreadPoolExecutor. > To resume, I have simplify my code, for example: > > for (int i = 0; i < 21; i++) { > new DownloadImageTask().execute("Test"); > } > > private class DownloadImageTask extends AsyncTask<String, Integer, > Bitmap> { > > public DownloadImageTask() { > super(); > } > > �...@override > protected Bitmap doInBackground(String... urls) { > try { > System.out.println("execute"); > Thread.sleep(10000); > } catch (InterruptedException e) { > e.printStackTrace(); > } > return null; > } > > �...@override > protected void onPostExecute(Bitmap result) { > } > } > > So, I think we can run 10 thread max and we have a pool of 10 thread > max. > > Can someone help me understand if there are limits on AsyncTask? If we > can modify the number of maw thread execution and the number max of > the pool? Or other idea ? > > Thanks > David > > > > -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---