AsyncTask is based upon the java.util.concurrent package's
ExecutorService and FutureTask classes.

When you create and execute an AsyncTask a thread is obtained from a
pool of threads (i don't know what the size of this pool is for
AsyncTasks) and your background process is executed on this thread.

If the pool-size is 1, then there will be always one background
thread. If another new AsyncTask is created and executed and an old
one is still busy doing its thing, the new one is queued and executed
only when the old one finishes.

If the pool-size is larger than 1, some algorithm kicks in
distributing the AsyncTasks over the threads in the pool.


On Jan 28, 12:32 pm, Biosopher <biosop...@gmail.com> wrote:
> I am performing several https posts and http downloads from two
> different servers using AsyncTasks.  The connections are fairly quick
> but I'm surprised to see that they are running synchronously instead
> of in parallel.
>
> To be more explicit, here is pseudo-code for what's happening when I
> initiate a call to AsyncTask1():
>
> AsyncTask1 {
>         for (i=1 to 3) {
>                 result = getDataFromServer1();
>                 moreDataUrl = parseResult(result);
>
>                 secondNetConnect = new AsyncTask2();
>                 secondNetConnect.doInBackground(moreDataUrl);
>         }
>
> }
>
> AsyncTask2 {
>         connects to 2nd server
>
> }
>
> What ends up running is this every time:
> AsyncTask1a, AsyncTask1b, AsyncTask1c, AsyncTask2a, AsyncTask2b,
> AsyncTask2c
>
> I would have expected at least some interleaving of the AsyncTask1 and
> AsyncTask2.  Is there a known issue with non-simultaneous network
> calls in Android using AsyncTask?
>
> Thanks,
> Anthony

-- 
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

Reply via email to