gpt4 book ai didi

android - AsyncTask、RejectedExecutionException 和任务限制

转载 作者:行者123 更新时间:2023-12-01 05:44:41 29 4
gpt4 key购买 nike

我正在使用 AsyncTask 从远程服务器获取大量缩略图并在 GridView 中显示它们。问题是,我的 GridView 一次显示 20 个缩略图,因此创建 20 个 AsyncTasks 并启动 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/6222999/

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