Android的AsyncTask的没有被要求对ICS分钟 [英] Android AsyncTask not being called for minutes on ICS
问题描述
我有一个使用了大量AsyncTasks的应用,我的问题是,一个特别重要的任务没有被启动了高达一两分钟后,我调用execute。
如果我用我的ICS的设备下面它的工作原理;
如果(Build.VERSION.SDK_INT> = 11)
{
myTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,东西);
}
,而不是本上$ P $对ICS;
myTask.execute(东西);
我知道,ICS已经改变线程执行被序列化,但我想不出是什么阻碍了线程队列中。
有在Eclipse调试上市约20线程,但我看了四周,调试倾向于保持显示那些是不是真的存在,也许这是不正确的。
我如何找出哪些线程阻碍了序列化队列,所以我不必从ICS默认切换,甚至改善这种arne't看到问题pre-ICS设备的性能由于线程池执行人是默认的行为。
我如何找出哪些线程阻碍了系列化队列
块引用>添加
登录
语句来追踪从出入境相关的doInBackground()
方法。
和甚至提高了arne't看到由于线程池执行人是默认行为的问题pre-ICS设备的性能。
块引用>您不需要使用
的AsyncTask
。只是餐桌自己的线程和使用的东西,如runOnUiThread()
作为主应用程序线程上执行逻辑后面的手段。的AsyncTask
是为了方便,而不是要求。而且,对于一个局外人高优先级任务,它可能会更有意义,你只需记住这远离任何线程池的争夺。或者,克隆和叉子
的AsyncTask
使用的PriorityQueue
,这样你就可以明确地指出你的高优先级任务I have an application that uses a lot of AsyncTasks, the problem I have is that a particularly important task is not being started for upto a couple of minutes after I call execute.
If I use the following for my ICS devices it works;
if(Build.VERSION.SDK_INT >= 11) { myTask.executeOnExecutor( AsyncTask.THREAD_POOL_EXECUTOR, stuff ); }
as opposed to this on pre-ICS;
myTask.execute(stuff);
I am aware that ICS has changed thread execution to be serialised but I can't figure out what is holding up the thread queue.
There are about 20 threads listed in debug in eclipse, but I have read around that perhaps this is not correct as the debugger tends to keep displaying ones that aren't really there.
How do I figure out which threads are holding up the serialised queue so i don't have to switch from the default on ICS, and perhaps even improve performance of pre-ICS devices that arne't seeing the problems due to the thread pool executor being default behaviour.
解决方案How do I figure out which threads are holding up the serialised queue
Add
Log
statements to track entry and exit from the relevantdoInBackground()
methods.and perhaps even improve performance of pre-ICS devices that arne't seeing the problems due to the thread pool executor being default behaviour.
You don't need to use
AsyncTask
. Just fork your own thread and use stuff likerunOnUiThread()
as a means of executing logic back on the main application thread.AsyncTask
is a convenience, not a requirement. And, for an outlier high-priority task, it may make more sense for you to simply keep that away from any thread pool contention.Or, clone and fork
AsyncTask
to use aPriorityQueue
, so you can explicitly indicate your high-priority tasks.这篇关于Android的AsyncTask的没有被要求对ICS分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!