有AsyncTasks的同时要执行的限制? [英] Is there a limit of AsyncTasks to be executed at the same time?

查看:187
本文介绍了有AsyncTasks的同时要执行的限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该有一个简单的答案,但我找不到任何。 而且因为我还是一个机器人假人我来这里是要问你的人。

This should have an easy answer, yet I couldn't find any. And since I'm still an android dummy I came here to ask you people.

我一直在做这个项目,执行10 AsyncTasks的启动。 每个任务包含收集的数据没有做任何重要的应用程序3个URL(还)。

I've been making this project that executes 10 AsyncTasks on the startup. Each task contains 3 URLs that collect data there and do nothing important in the app (yet).

我也有10 textviews我用跟踪的AsyncTasks的进度。

I also have 10 textviews which I use to keep track of the progress of the AsyncTasks.

当一个任务启动相应的TextView放在启动 当一个任务进展它会将其相应的TextView到下载 当任务完成后它会将其相应的TextView为完成

When a task starts the appropriate textview is put on "Start" When a task is progressing it sets its appropriate textview to "Downloading" When a task is finished it sets its appropriate textview to "Finished"

这是我所观察到的,来到质疑有关AsyncTask的。 当我启动应用程序,我注意到5 textviews被切换到下载的标记,所以我看到5 AsyncTasks做他们的工作,因为他们应该。完成后它启动了一个新的AsyncTask。但他们从来没有达到过5的限制。

This is what I observed and came to question about the AsyncTask. When I start the app I notice 5 of the textviews being switched to the "Downloading" marker, so I see 5 AsyncTasks doing their job as they should. When done it starts up a new AsyncTask. Yet they never reach over that limit of 5.

是什么原因导致在同一时间运行5 AsynchTasks这个限制? 我是不是导致此中,我无法找到一些文件? 这也是Android 2.3.3的限制?也许我使用到SIM卡应用程序?设备的限制

What causes this limit of 5 AsynchTasks running at the same time? Did I cause this in some file which I cannot find? Is this a limit of android 2.3.3? Maybe a limit of the device I'm using to sim the app?

谁能详细给我吗?

推荐答案

是的,有一个限度。 的AsyncTask 被支持的<一个href="http://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html"><$c$c>ThreadPoolExecutor为5的核心池大小,但128的最大池大小(从1.6 - 4.0.3),所以我真的想你应该看到所有10的你同时运行。你不能改变,虽然它。如果你真的想要做不同的事情(我不会推荐它,除非你有一个非常特殊的理由),你必须做一些定制具有较大的池大小,或只是旋转起来一堆手动线程。

Yes, there's a limit. AsyncTask is backed by a ThreadPoolExecutor with a core pool size of 5, but a maximum pool size of 128 (from 1.6 - 4.0.3), so really I would think you should see all 10 of yours run at once. You can't change it though. If you really want to do something different (and I wouldn't recommend it unless you have a very specific reason), you'll have to do something custom with a larger pool size or just spin up a bunch of threads manually.

更新:

下面就是文档说:

如果有比corePoolSize以上但小于运行maximumPoolSize线程,一个新的线程将创建仅当队列满

If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full.

所以这就是为什么。您的队列不充分,所以它只是把它放在核心池的大小。

So that's why. Your queue isn't full, so it just keeps it at the core pool size.

这篇关于有AsyncTasks的同时要执行的限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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