多少AsyncTasks我可以在单个进程中运行的应用程序

多少AsyncTasks我可以在单个进程中运行的应用程序

本文介绍了多少AsyncTasks我可以在单个进程中运行的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asyncTasks,用来加载图像列表元素(只是跟着Android的有效装载位图的教程)

I am using asyncTasks, to load list elements with images (Just followed android's tutorial of efficiently loading bitmaps)

在DDMS,我可以看到高达5 As​​yncTasks是运行

In DDMS, i can see upto 5 AsyncTasks being running

现在除了我已经增加了一个AsyncTask的,使用Media codeC类执行一些解码。

Now in addition i have added another AsyncTask, which performs some decoding using MediaCodec class.

现在在DDMS,我仍然看到5 AsyncTasks,我的图像加载aynctask或解码异步执行任务,而不是他们两个。

Now in DDMS, i still see 5 AsyncTasks, and my image loading aynctask or decoding async task executes, not both of them.

在解码运行时,如果我滚动列表,也不会更新元素的图像
Counterly当我通过调用它的执行方法,推出新的解码的AsyncTask,解码不会启动,但如果我现在滚动列表视图,图像更新。

When decoding is running, if i scroll the list, elements' images are not updatedCounterly when i launch new decoding asynctask by calling it's execute method, the decoding doesn't start, but if i scroll the list view now, the images are updated.

原来是AsyncTask的是limitted ??

So is AsyncTask is limitted??

即使在listAdapter我每次推出电话getView的AsyncTask的。我已经期待7运行asyncTasks(如果列表中可见元素是7,说),但DDMS只显示5运行asynctasks。

Even in listAdapter i launch an AsyncTask per getView call. I'd expecting 7 running asyncTasks (if list visible elements are 7, say), but DDMS shows only 5 asynctasks running.

现在能有人解释我有什么魔法,我不能拼?

Now can someone explain me what's the black magic that i can't spell?

推荐答案

多少 AsyncTasks 你可以同时运行?

How many AsyncTasks can you run at once?

在Android的大多数版本,答案是的 128

In most versions of Android, the answer is 128.

为什么你通常​​清楚地看到5 的AsyncTask 主题?

Why will you generally see exactly 5 AsyncTask threads?

的AsyncTask 线程管理相当混乱,尤其是自从第一款Android版本已经改变了很多。

AsyncTask thread management is rather confusing, especially since it has changed a lot since the first Android release.

在新的Andr​​oid版本中,5个线程,默认情况下创建和的ThreadPoolExecutor 将尝试运行的AsyncTask S于这5个线程。如果您创建超过5 的AsyncTask S,它既可排队它们或创建新的线程(但最多只能到128)。

In newer Android versions, 5 threads are create by default, and the ThreadPoolExecutor will attempt to run the AsyncTasks on these 5 threads. If you create more than 5 AsyncTasks, it may either queue them or create new threads (but only up to 128).

请注意,在早期版本的Andr​​oid,这些限不同。我相信,原来,有永远只能有一个线程创建了。

Note that in earlier versions of Android, these limits were differently. I believe that, originally, there was only ever one thread created.

但是,所有的图像最终应加载...

要回答你的问题的另一部分,除非你加载大量的图片(其中很多是指> 128),所有的图像应加载,但可能顺序。如果第5负荷,其余不这样做,这可能表明你的 doInBackground()函数永远不会完成或者有别的毛病 AsyncTask的您使用。

To answer the other part of your question, unless you're loading a lot of images (where a lot means >128), all the images should load, although likely sequentially. If the first 5 load and the rest do not, that might indicate that your doInBackground() function is never finishing or there is something else wrong with the AsyncTask you are using.

资源:

下面是学习更多有关的AsyncTask 线程管理一些有用的资源:

Here are some helpful resources for learning more about AsyncTask thread management:

Is有AsyncTasks的限制的同时被执行?

这篇关于多少AsyncTasks我可以在单个进程中运行的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:55