Reputation:
When executing AysncTask
, The following api I am using
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,"nameofpool");
Is it possible that somehow I can set only 2 threads limit in this pool.
Upvotes: 1
Views: 1661
Reputation: 39403
The AsyncTask.THREAD_POOL_EXECUTOR
is a special pool that is created for you and administrated by Android.
You can, however, create your own Executor
, typically using :
Executor myExecutor = Executors.newFixedThreadPool(2);
which you can use in your AsyncTask
:
executeOnExecutor(myExecutor, params);
Nota: please note that your param "nameofpool" is actually the parameter to the doInBackground
method on your AsyncTask
, and is not related to the Thread pool management.
Upvotes: 3
Reputation: 328923
You can provide your own executor:
executeOnExecutor(Executors.newFixedThreadPool(2), "nameofpool");
Upvotes: 2