user435739
user435739

Reputation:

How to limit the threads in the thread pool (Android)

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

Answers (2)

njzk2
njzk2

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

assylias
assylias

Reputation: 328923

You can provide your own executor:

executeOnExecutor(Executors.newFixedThreadPool(2), "nameofpool");

Upvotes: 2

Related Questions