Android的AsyncTask的没有被要求对ICS分钟 [英] Android AsyncTask not being called for minutes on ICS

查看:148
本文介绍了Android的AsyncTask的没有被要求对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 relevant doInBackground() 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 like runOnUiThread() 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 a PriorityQueue, so you can explicitly indicate your high-priority tasks.

这篇关于Android的AsyncTask的没有被要求对ICS分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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