其次AsyncTask的不执行 [英] Second AsyncTask not executing

查看:154
本文介绍了其次AsyncTask的不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2 AsyncTask的,其中之一是建立一个套接字连接并anotherone正在传送使用这些插槽的对象。我的code是这样的:

I have 2 AsyncTask, one which is creating a socket connections and anotherone that is transmitting objects using those sockets. my code is this:

try {
        connectat = true;
        transmitter = new SocketTransmitter();
        transmitter.execute();
        connector = new socketConnector();
        connector.execute(owner);

        this.open();
    } catch (IOException e) {

不过,的AsyncTask 名为 socketConnector 永远不会创建或执行。我试图改变顺序,但随后变送器没有建立或执行...

However, the AsyncTask called socketConnector is never created or executed. I tried to change the order but then transmitter is not created or executed...

请告诉我错了吗?

推荐答案

我讨厌它,当蜂巢变多AsyncTask的执行并发至顺序。 所以,我每次执行AsyncTask的,我做这样的事情。

I hated it when HONEY COMB changed the multiple AsyncTask execution from concurrent to sequential. So every time I execute an AsyncTask, I do something like this.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
    task.execute();
}

但是线程池的大小是5,如果添加的第六任务,它会在一个队列中,并将不会直到5线程已完成1执行。

But the thread pool size is 5, if you add the sixth task, it will be added in a queue, and will not be executed until one of the 5 thread has finished.

这篇关于其次AsyncTask的不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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