2012/4/20 Kostya Vasilyev <[email protected]>:
> The default is definitely serial on my GNex with 4.0.2.
>
> Did they revert it again for the 4.0.3 that you have?

Here's how I am testing it (sloppy code, but it meets the need):

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;

public class ParallelTasksActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    new SillyTask().execute("A");
    new SillyTask().execute("B");
    new SillyTask().execute("C");
    new SillyTask().execute("D");
    new SillyTask().execute("E");
  }

  class SillyTask extends AsyncTask<String, String, Void> {
    @Override
    protected Void doInBackground(String... params) {
      for (int i=0; i < 5; i++) {
        String msg=params[0] + String.valueOf(i);

        Log.d("ParallelTasks", msg);
        SystemClock.sleep(1000);
      }

      return(null);
    }
  }
}

Now, if AsyncTask executes serially, I would expect:

A0
A1
A2
A3
A4
B0
B1
B2
B3
B4
...

Even if the letters were out of order (e.g., C before A), the
numerical index would be in order, because the task would be tying up
the one-and-only thread, so there should be no interleaving between
letter.

Yet, when I run this on 4.0.3 or 4.0.4, I get:

04-20 20:15:34.574: D/ParallelTasks(2965): D0
04-20 20:15:34.574: D/ParallelTasks(2965): C0
04-20 20:15:34.574: D/ParallelTasks(2965): E0
04-20 20:15:34.582: D/ParallelTasks(2965): A0
04-20 20:15:34.586: D/ParallelTasks(2965): B0
04-20 20:15:35.574: D/ParallelTasks(2965): D1
04-20 20:15:35.574: D/ParallelTasks(2965): E1
04-20 20:15:35.574: D/ParallelTasks(2965): C1
04-20 20:15:35.582: D/ParallelTasks(2965): A1
04-20 20:15:35.586: D/ParallelTasks(2965): B1
04-20 20:15:36.578: D/ParallelTasks(2965): E2
04-20 20:15:36.578: D/ParallelTasks(2965): C2
04-20 20:15:36.586: D/ParallelTasks(2965): D2
04-20 20:15:36.586: D/ParallelTasks(2965): A2
04-20 20:15:36.589: D/ParallelTasks(2965): B2
04-20 20:15:37.586: D/ParallelTasks(2965): C3
04-20 20:15:37.593: D/ParallelTasks(2965): D3
04-20 20:15:37.593: D/ParallelTasks(2965): B3
04-20 20:15:37.593: D/ParallelTasks(2965): E3
04-20 20:15:37.593: D/ParallelTasks(2965): A3
04-20 20:15:38.589: D/ParallelTasks(2965): C4
04-20 20:15:38.601: D/ParallelTasks(2965): D4
04-20 20:15:38.601: D/ParallelTasks(2965): E4
04-20 20:15:38.605: D/ParallelTasks(2965): B4
04-20 20:15:38.609: D/ParallelTasks(2965): A4

Since the five AsyncTask instances are interleaving their results, I
have to assume that they are running in parallel.

Even if I change doInBackground() to:

    @Override
    protected Void doInBackground(String... params) {
        Log.d("ParallelTasks", params[0] + " started");
        SystemClock.sleep(10000);
        Log.d("ParallelTasks", params[0] + " ended");

      return(null);
    }

so there's a 10-second tie-up, I get:

04-20 20:20:02.886: D/ParallelTasks(3044): D started
04-20 20:20:02.898: D/ParallelTasks(3044): B started
04-20 20:20:02.898: D/ParallelTasks(3044): A started
04-20 20:20:02.898: D/ParallelTasks(3044): E started
04-20 20:20:02.898: D/ParallelTasks(3044): C started
04-20 20:20:12.898: D/ParallelTasks(3044): A ended
04-20 20:20:12.902: D/ParallelTasks(3044): C ended
04-20 20:20:12.910: D/ParallelTasks(3044): D ended
04-20 20:20:12.914: D/ParallelTasks(3044): B ended
04-20 20:20:12.918: D/ParallelTasks(3044): E ended

All five start, 10 seconds elapses, and all five end, indicating that
they are running in parallel.

Where I am going wrong in my analysis?

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.7 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to