使用executeOnExecuter可以进行多少次并行执行? [英] How many parallel execution possible using executeOnExecuter?

查看:139
本文介绍了使用executeOnExecuter可以进行多少次并行执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当用户从列表中点击文档时,我需要为文档提供下载功能.

In my application I need to provide download functionality for document when user tap on document from list.

因此,对于多个活动线程,AsyncTask进入了我的脑海.但是我也注意到人们并不推荐AsyncTask进行这种操作.因为在这种情况下大号.线程将开始点击文件.

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.

不采用AsynTask的另一个原因是现代AsyncTask仅限于128个并发任务".意味着如果您在完成138个任务之前排队,则您的应用程序将崩溃.

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.

  1. executeOnExecutor()方法是否可以解决我的目的,或者我需要重新考虑它?
  2. 如果我同时启动50个任务,那么所有这些任务都通过executeOnExecutor()运行simeltenioulsy吗?
  3. 并发任务限制(128)是否也适用于executeOnExecutor()?

我希望得到完美的答案.

I expect perfect answer.

推荐答案

不采用AsynTask的另一个原因是现代AsyncTask仅限于128个并发任务".意味着如果您在完成138个任务之前排队,则您的应用程序将崩溃.

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.

更准确地说,AsyncTask的内置执行程序使用128元素的工作队列来处理正在等待线程的请求.但是请注意,此限制未记录在案,并且可能会发生变化.

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.

executeOnExecutor()方法会解决我的目的

Will executeOnExecutor() method solve my purpose

这完全取决于您提供给executeOnExecutor()的哪种Executor.

That depends entirely upon what sort of Executor that you supply to executeOnExecutor().

如果我同时启动50个任务,那么所有这些任务都通过executeOnExecutor()运行simeltenioulsy吗?

If I start 50 task at same time then all these task run simeltenioulsy by executeOnExecutor()?

不.对于初学者来说,您的CPU没有那么多内核.

No. For starters, your CPU does not have that many cores.

并发任务限制(128)是否也适用于executeOnExecutor()?

Concurrent task limit(128) also applicable to executeOnExecutor()?

仅当您使用该限制设置Executor时.如果您使用两个内置的AsyncTask执行程序(SERIAL_EXECUTORTHREAD_POOL_EXECUTOR)之一,则可以,该队列限制应该到位.

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.

这篇关于使用executeOnExecuter可以进行多少次并行执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆