The default, starting with 4.0, is to use the serial executor: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/AsyncTask.java#L192
But there is also an way to explicitly use the thread pool executor: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/os/AsyncTask.java#L536 i.e.: new MyAsyncTask(....).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ....); Or you could supply your own executor parameter that's constructed outside of AsyncTask. The predefined thread pool executor "constant" is new with API 11 (Android 3.0). -- K 20 апреля 2012 г. 23:16 пользователь Nathan <nathan.d.mel...@gmail.com>написал: > Still adjusting to the changes in Android 4.0 regarding AsyncTask. > > If I understand right, the default behavior of execute is changing to one > single thread pool with only one thread? With the reason cited that > programmers are not capable of handling a bigger threadpool (I'm > paraphrasing). > > Does that mean, that absent some code changes, all asynctasks inside a > process will only happen sequentially? > > So therefore, if I have a service running DownloadDictionaryTask in the > background, and the user chooses a menu item that starts > CheckDiskSpaceTask, the progress bar will cycle without any progress > because the task never makes progress? > > A user and I could briefly reproduce a situation where, as far as I could > tell, no asynctasks were running, yet my AsyncTask would not even start. In > this case, I couldn't even get one thread. Alas, I cannot reproduce that > situation, which appeared to fix itself without any code changes. > > But in any case, this isn't really acceptable to have only one asynctask > task run at once. But there is no central way to control that behavior, is > there? I would have to replace 83 instances of task.execute with > task.executeonExecutor. Since the above method is only available in SDK>11, > this isn't a one line change - it's more like 10-20 lines of code with > reflection, and some extensive testing. > > In my opinion, this a deplorable punishment for those developers who have > dutifully followed the AsyncTask pattern, which, to this day, the Android > platform has encouraged. > > Or perhaps I am reading this wrong. Maybe all DownloadDictionaryTasks > share one pool, and all CheckDiskSpaceTasks share another pool. In that > case, the rule is that only one task *of the same concrete type* can run at > once. This rule, I can probably live with, as I've used my own threading > pools for tasks that are truly data parallel. > > Can anyone enlighten me more? > > 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 -- 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