Home » Android » Run Multiple Asyntask at the same time [duplicate]

Run Multiple Asyntask at the same time [duplicate]

Posted by: admin November 1, 2017 Leave a comment


This question already has an answer here:


You probably want to execute all Asynctasks at the same time in ThreadPool

asyncTask1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ....);

AsyncTask.THREAD_POOL_EXECUTOR is a constant Executor. If you’re not satisfied on AsyncTask’s Thread pool. You can create your own thread pool by doing this.

Executor myThreadPool = Executors.newFixedThreadPool(numOfPools);

Usually, numOfPools is taken from available processors by Runtime.getRuntime().availableProcessors().

It is still up to you how many threads you want. Be aware of battery use. More computation power, more battery. Just a reminder.