ASyncTasks blocking others

后端 未结 3 1250
梦谈多话
梦谈多话 2021-01-31 16:37

I\'ve 2 ASyncTasks, one retrieves a value from an httpPost and the other update some elements of the UI (including an listview). The problem is that since both ASyncTasks share

3条回答
  •  死守一世寂寞
    2021-01-31 17:12

    The problem is that every AsyncTask run in the same ThreadPoolExecutor which is coded into the API. This ThreadPoolExecutor can create a different number of WorkerThread depending on your Android version. I don't remember the number versions but the idea is that in older Android versions it was 1 WorkerThread. Then it was updated to 5 in later versions. And recently got moved back to 1 again. This is why your AsyncTasks are blocked. They run all on the same WorkerThread and thus they execute sequentially. Try using executeOnExecutor with THREAD_POOL_EXECUTOR to achieve true parallel execution. However you can use this only since API 11.

提交回复
热议问题