AsyncTask的,RejectedExecutionException和任务限制 [英] AsyncTask, RejectedExecutionException and Task Limit

查看:127
本文介绍了AsyncTask的,RejectedExecutionException和任务限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我获取大量的缩略图从远程服务器,并在网格视图中显示它们,使用AsyncTask的。问题是,我的网格视图中显示20个缩略图的时间,使创建20 AsyncTasks并启动20执行,每个缩略图之一。

我在code获得 RejectedExecution 例外。回想读书的地方,有一个限制的任务数的AsyncTask可以同时在其队列中,我可能被击中这一点。是这样的吧解除?

有没有办法来增加此限制?它是安全的忽略这个异常?(由具有空赶上(RejectedException E){} 块?)

我运行此$ C $在Android 1.6模拟器在我的code C和API级别(的minSdkVersion是3)。

解决方案
  

我记得读了某个地方有   是有限的任务数   AsyncTask的可以在一个具有在其队列   一次,我可能会被打的。当时   这个酒吧取消?

的AsyncTask 显得presently支持10个线程和10。从理论上讲一个工作队列深度,这将仅仅支持20个项目......如果不出意外是使用的AsyncTask

  

有没有办法来增加此限制?

抓住源头code,修改它,把它放在你自己的包,并使用该之一。我这样做是我的 AsyncTaskEx ,尽管这是基于Android 1.5的源代码。

  

它是安全的忽略此   例外?

您的工作将不会排队等待执行。无论是安全的是你。我不知道对的AsyncTask 基础设施的任何其他方面的影响。

I am fetching lots of thumbnails from a remote server and displaying them in a grid view, using AsyncTask. The problem is, my grid view displays 20 thumbnails at a time, so that creates 20 AsyncTasks and starts 20 executes, one per thumbnail.

I get RejectedExecution exception in my code. 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?

Is there a way to increase this limit? Is it safe to just ignore this exception?(by having an empty catch(RejectedException e){} block?)

I am running this code on Android 1.6 emulator and the API level in my code(minSDKVersion is 3). [EDIT: Added SDK and API level info]

解决方案

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 appears to presently support 10 threads and a work queue depth of 10. In theory, that would just support 20 items...if nothing else is using AsyncTask.

Is there a way to increase this limit?

Grab the source code, modify it, put it in your own package, and use that one. I did this with my AsyncTaskEx, though that is based on the Android 1.5 source.

Is it safe to just ignore this exception?

Your work will not be queued for execution. Whether that is "safe" is up to you. I am not aware of any other impacts on the AsyncTask infrastructure.

这篇关于AsyncTask的,RejectedExecutionException和任务限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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