Google is probably aware of the limitations of Asynctask and has made some tweaks to Asynctask's API starting with Android 3.0: The task submitted by #execute () has added two predefined thread pools Serial_executor ( The default is the sequence thread pool, which executes only one thread task at a time ) and Thread_pool_executor ( also the original default thread pool )
Run only one at a time in order, that is, it is in the order of submission, each time only one thread is started to perform a task, and then a second task is completed, which is equivalent to only one background thread executing the submitted task (Executors.newsinglethreadpool ())
Added interface #executeonexecutor () This interface allows developers to provide custom thread pool run and dispatch thread, if you want all tasks to run concurrently concurrently, create an unrestricted thread pool ( Executors.newcachedthreadpool ()) and provided to Asynctask. This asynctask instance has its own thread pool instead of using the Asynctask default.
In fact, Thread_pool_executor is not new, before it, just before (Android 2.3) It is asynctask private, not public. thread_pool_executor is a thread pool with a corepoolsize of 5, which means that at most 5 threads run at the same time, more than 5 will wait. So
If you use executeonexecutor (asynctask. Thread_pool_executor ) is the same as the 2.3 version of the Asynctask.execute () effect.
and Serial_executor is new, it is to ensure the order of the task execution, that is, it can ensure that the task is committed in order to do in sequence. It has a queue inside it to hold the submitted task, ensuring that only one is currently running, so that the task is executed in exactly the order that the default execute () uses, that is, Executeonexecutor (asynctask. Serial_executor) is the same as execute ().