One strange thing that I've seen in my usage of AsycTask is that the Thread associated with an AsyncTask seems to live on after the task has completed. It appears to be in some kind of idle/finalized state, but the resources associated with the Thread itself remain visible in the debugger. As far as I can tell, the task has completed and exited normally. Subsequent invocations of the task seem to create a new thread in the process.
Is this some kind of optimization? A leak? A misuse of AsyncTask? I've never spent a huge amount of time on figuring it out, as the use case for me was fairly fringe, but I've wondered about it... On Nov 11, 11:25 am, Romain Guy <romain...@google.com> wrote: > Please consider the implications of this: does it even make sense to > have 20+ threads (on a single CPU device) updating the UI at once? > That is NOT the purpose of AsyncTask. Also, since Donut, the limit of > enqueued tasks in AsyncTask is 128, not 20. So AsyncTask has a maximum > of 10 threads running concurrently and can hold up to 128 tasks > waiting for a thread to be freed in the pool. So basically AsyncTask > does exactly what you are trying to do here. > > > > > > On Wed, Nov 11, 2009 at 1:02 AM, Atif Gulzar <atif.gul...@gmail.com> wrote: > > Android has a limit to rum at MAX 20 concurrent AsyncTask. To handle this > > limit I created a AsyncTaskPool.java utility. Its not a pool in true sense > > but a kind of scheduler. I am posting it here for your comments and it may > > help others. > > > import java.util.ArrayList; > > > import android.os.AsyncTask; > > > public class AsyncTaskPool > > { > > > private int poolSize; > > private ArrayList<AsyncTask> currentTasks = new ArrayList<AsyncTask>(); > > private ArrayList<Object> pendingTasks = new ArrayList<Object>(); > > > /** > > * @param poolSize > > * : it should be less than 20. As Android only supports max. > > 20 concurrent Asynch tasks. > > */ > > public AsyncTaskPool(int poolSize) > > { > > this.poolSize = poolSize; > > } > > > public int getPoolSize() > > { > > return poolSize; > > } > > > public boolean addTask(AsyncTask asyncTask, Object... params) > > { > > > if (currentTasks.size() < poolSize) > > { > > currentTasks.add(asyncTask); > > if (params != null) > > asyncTask.execute(params); > > else > > asyncTask.execute(); > > } > > else > > { > > Object[] task = new Object[2]; > > task[0] = asyncTask; > > task[1] = params; > > > pendingTasks.add(task); > > } > > > return true; > > } > > > public boolean removeTask(AsyncTask task) > > { > > if(currentTasks.contains(task)) > > { > > currentTasks.remove(task); > > return true; > > } > > return false; > > } > > > //Add this method in the onPostExecute method of AsyncTask > > public boolean removeAndExecuteNext(AsyncTask atask) > > { > > removeTask(atask); > > if (pendingTasks.size()>0 && currentTasks.size()<poolSize) > > { > > Object [] task = (Object []) pendingTasks.get(0); > > pendingTasks.remove(task); > > > addTask((AsyncTask)task[0], (Object[])task[1]); > > > } > > > return false; > > } > > > } > > > -- > > Best Regards, > > Atif Gulzar > > > I ◘◘◘◘ Unicode, ɹɐzlnƃ ɟıʇɐ > > > -- > > 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 > > -- > 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- Hide quoted text - > > - Show quoted text - -- 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