Reputation: 1858
In my application I need to provide download functionality for document when user tap on document from list.
So, for multiple active threads AsyncTask come into my mind. But I also noticed that people have not recommended AsyncTask for this kind of operation. Because in this case large no. of thread will get start on tapping of document.
Another reason to don't take AsynTask is that "The modern AsyncTask is limited to 128 concurrent tasks". Means that if you queue up more than 138 tasks before they can complete, your app will crash.
I expect perfect answer.
Upvotes: 1
Views: 221
Reputation: 1007399
Another reason to don't take AsynTask is that "The modern AsyncTask is limited to 128 concurrent tasks". Means that if you queue up more than 138 tasks before they can complete, your app will crash.
More accurately, AsyncTask
's built-in executors use a 128-element work queue to handle requests that are waiting for threads. Note, though, that this limit is not documented and is subject to change.
Will executeOnExecutor() method solve my purpose
That depends entirely upon what sort of Executor
that you supply to executeOnExecutor()
.
If I start 50 task at same time then all these task run simeltenioulsy by executeOnExecutor()?
No. For starters, your CPU does not have that many cores.
Concurrent task limit(128) also applicable to executeOnExecutor()?
Only if you set up your Executor
with that limit. If you use one of the two built-in AsyncTask
executors (SERIAL_EXECUTOR
, THREAD_POOL_EXECUTOR
), then yes, that queue limit should be in place.
Upvotes: 1