第二个 AsyncTask 没有执行 [英] Second AsyncTask not executing

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

问题描述

我有 2 个 AsyncTask,一个创建套接字连接,另一个使用这些套接字传输对象.我的代码是这样的:

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) {

然而,永远不会创建或执行名为 socketConnectorAsyncTask.我尝试更改订单,但未创建或执行传输器...

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

这有什么问题吗?

推荐答案

当 HONEY COMB 将多个 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,如果添加第6个任务,它会被添加到一个队列中,直到5个线程中的一个完成后才会执行.

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天全站免登陆