简体   繁体   中英

Is android async task slow?

Is android async task slow or am i doing something wrong?

Here is what i do

Log.e("Filler", "before");
new DownloadListContent().execute("string");
Log.e("Filler", "after");

and DownloadListContent()..

class DownloadListContent extends AsyncTask<Object, Object, Object> {
    protected Void doInBackground(Object... urls) {             
    Log.e("Filler", "Am in doInBackground");

....
}

And here is the logCat.

03-15 23:18:**47**.598: E/Filler(17150): before
03-15 23:18:**47**.598: E/Filler(17150): after
03-15 23:18:**59**.789: E/Filler(17150): Am in doInBackground

That is 12 seconds before do in background occurs. Why is that happening?

In the mean time i have other instances of other classes of AsyncTask do some other network jobs. Does AsyncTask affects one an other?

I really cannot figure that one out!

UPDATE

Thank you for the comments. seems that async has a hard limit on how many threads will run at the same time. This is a killer if you have to download a bunch of images at the same time with your data.

Following CommonsWare's method here i can seperate the type of asyncTask so that one type (images) don't block other type (list data).

Right, it does have limited pool of threads. On Honeycomb, the pool size is one, so you can't have two tasks at the same time. You can supply your own executor though, to have multiple tasks run in parallel. That might not improve performance though, so you should maybe think of restructuring your code a bit:

http://developer.android.com/reference/android/os/AsyncTask.html#executeOnExecutor(java.util.concurrent.Executor , Params...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM