-1

I have an Android application that uses AsyncTasks to make get and post calls to send and retrieve data from server. All works fine but sometimes the async task takes a lot of time to execute and thus other async tasks have to wait (if more than 5 async tasks is there) so what will be the best alternative or how to increase the thread pool if it is safe to do so.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58

1 Answers1

1

Asynctask are implemented behind the scene using threadpool, the default pool size for asynctasks is 1(so you can't run 2 asynctasks in parallel). In newer versions of android the default Asynctask pool size is 5. It's possible to change it but not recommended.

You can just create thread like in the sample I attached before:

Thread thread = new Thread() {
    @Override
    public void run() {
        try {
                //Do http request here
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
};

thread.start();
Ben
  • 129
  • 1
  • 3