0

In my android application, I have to get almost 50 data (50 AsyncTask) from server parallel y. So I implemented my logic by using executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);. And I read about executeOnExecutor which can run only 5 AsyncTask at a time and it has a queue of size 10. Where we can keep maximum 10 pending AyncTask. Ok, now in my scenario I have 50 AsyncTask and I can't execute 50 AsyncTask together parallel y because the queue have size only 10. So I can't go with approach of executing 50 AsyncTasktogether.

So I came up with an other logic, there I will create and execute 5 AyncTask together. And I will start new AysncTask on call back of each already executed AsyncTask.

The second logic satisfied my requirement. It is working perfectly.

Note: Here I'm using my own AsyncTask class and I'm making http request by using Apache http client.

Now, newly I heard about a library called android-async-http. I wanted to reimplement the above logic with this library.

Sample code:

AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.google.com", new AsyncHttpResponseHandler() {
    @Override
    public void onSuccess(String response) {
        System.out.println(response);
    }
});

So my question is,

  • How do I execute http request parallel y by using android-async-http library?

  • What is the maximum number of AsyncTask I can execute parallel y by using this library?

TeaDrivenDev
  • 6,591
  • 33
  • 50
Vishal Vijay
  • 2,518
  • 2
  • 23
  • 45

1 Answers1

1

Turns out this library you are using uses a CachedThreadPool: http://www.blogjava.net/dashi99/archive/2012/08/06/384885.html

Which means that if you execute a lot of requests it will create threads to execute them accordingly. it will reuse threads for the requests if the threads are free and not shut down. So i assume this means that all your requests will run in parallel.

DArkO
  • 15,880
  • 12
  • 60
  • 88