On Friday, 20 April 2012 23:24:34 UTC+2, Dianne Hackborn wrote:
>
> Yes if your targetSdkVersion is >= 12, then as of that release the default
> executor is serial.
>
> This change was made because we realized we had a lot of bugs in the
> platform itself where async tasks where created that had implicit ordering
> dependences, so with the default parallel execution there were subtle rare
> bugs that would result.
>
While I understand why this change why made it introduced some subtle bugs
in apps running on ICS with the SerialExecutor vs the the Threaded Executor.
It is unfortunate and I'm not sure it was a wise decision to change such an
important behaviour that late.
Notably, lots of app uses AsyncTask to do networking I/O for which you can
spend quite a lot of time in doInBackground() for example if the connection
timeout or is
very slow. This is not uncommon on mobile networks.
Consider such an AsyncTask blocked for several seconds (maybe 20s or 30s)
in doInBackground(). With the serial executor it blocks *all pending*
AsyncTask in the queue until it finishes.
So it can give to the user the app is frozen or that something that should
happening or be updated isn't. That's a new kind of ANR without an actual
ANR.
To summarize, all apps who used AsyncTask assuming parallel execution are
possibly broken if doInBackground() does not finishes quick.
When I explained this to a well know Google engineer, I was told : "You
fool! thou shall use AsyncTask only for short lived task! Use your own
AsyncTask replacement for long-running parallel tasks". Don't get even me
started on the scientific definition of "short lived task"...
In the end since I knew why I need the ThreadDed executor, I just wrapped
all my AsyncTask execution with this function:
static public <T> void executeAsyncTask(AsyncTask<T,?,?> task, T... params)
{
if(isHoneycombOrLater()) {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
} else {
task.execute(params);
}
}
Conclusion: there's probably man apps broken in subtle ways on ICS because
of this change.
--
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