On Friday, April 20, 2012 3:26:26 PM UTC-7, b0b wrote: > > > > 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"... > > B0b's concerns echo my own.
If you don't use an AsyncTask, you'll get an ANR. But if you do, you have a progress bar that never moves because something else is running, and the users will think it is frozen. Nowhere have I been told that AsyncTasks were only for short lived tasks (like a few seconds). I have used it for longer tasks. And I've never really assumed that it was safe to use it for task with dependencies between them. If the platform is using the AsyncTask internally, it better be short lived tasks. Nonetheless, I can't disagree with Diane's lesson that multithreading is hard. But the other thing I've learned about threads is that I always seem to need more of them. Nathan -- 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