gpt4 book ai didi

android - AsyncTask、RejectedExecutionException 和任务限制

转载 作者:IT老高 更新时间:2023-10-28 23:40:59 31 4
gpt4 key购买 nike

我正在从远程服务器获取大量缩略图,并使用 AsyncTask 在 GridView 中显示它们。问题是,我的 GridView 一次显示 20 个缩略图,因此创建 20 个 AsyncTask 并启动 20 个执行,每个缩略图一个。

我的代码中出现 RejectedExecution 异常。我记得在某处读到 AsyncTask 一次可以在其队列中拥有的任务数量是有限制的,我可能会遇到这个问题。这个栏被取消了吗?

有没有办法增加这个限制?忽略这个异常是否安全?(通过有一个空的 catch(RejectedException e){} block ?)

我在 Android 1.6 模拟器和我的代码中的 API 级别上运行此代码(minSDKVersion 为 3)。[编辑:添加了 SDK 和 API 级别信息]

最佳答案

I recall reading somewhere that there is a limit to number of tasks that AsyncTask can have in its queue at a time, i might be hitting that. Was this bar lifted?

AsyncTask 目前似乎支持 10 个线程和 10 个工作队列深度。理论上,这将只支持 20 个项目...如果没有其他使用 AsyncTask .

Is there a way to increase this limit?

获取源代码,对其进行修改,将其放入您自己的包中,然后使用那个。我用我的 AsyncTaskEx 做了这个,尽管它基于 Android 1.5 源代码。

Is it safe to just ignore this exception?

您的工作不会排队等待执行。这是否“安全”取决于您。我不知道对 AsyncTask 基础架构有任何其他影响。

关于android - AsyncTask、RejectedExecutionException 和任务限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2492909/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com