1

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.

assylias
  • 310,138
  • 72
  • 642
  • 762

2 Answers2

3

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.

njzk2
  • 38,125
  • 7
  • 64
  • 103
2

You can provide your own executor:

executeOnExecutor(Executors.newFixedThreadPool(2), "nameofpool");
assylias
  • 310,138
  • 72
  • 642
  • 762