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

查看:15
本文介绍了使用 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() 运行吗?
  3. 并发任务限制(128) 也适用于executeOnExecutor()?

我期待完美的答案.

推荐答案

不采用 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() 运行吗?

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天全站免登陆