Can we create two ThreadPoolExecutor running on android?
AsyncTask is managing a thread pool with 5 core thread. Once we start to use AsyncTask, it wil开发者_如何学编程l start to set up this thread pool on android phone.
The reason I don't want to AsyncTask is because I am going to create a service, and start threads from service, which means there is not much UI updates from task. However, asynctask has to been created and execute on UI thread.
So I am going to create another different thread pool which will be used to manage this kind of threads. What I am worrying about is that if I create another thread pool with 5 core threads, would that be too much threads(10 core threads) running on the android? will that slow it down and cause bad performance?
Thanks.
As Alex said ,You will need to use method executeOnExecutor()
to start it with your own executor.
http://developer.android.com/reference/android/os/AsyncTask.html#executeOnExecutor%28java.util.concurrent.Executor,%20Params...%29
There seems to be number of gotchas, so read carefully the entire page for AsyncTask
.
So yes, you can create your own ThreadPoolExecutor
and use it with AsyncTask
.
And also check this,
Using ThreadPoolExecutor and AsyncTask
精彩评论