Second AsyncTask not executing(第二个 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) {
然而,永远不会创建或执行名为 socketConnector
的 AsyncTask
.我尝试更改订单,但未创建或执行传输器...
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 没有执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:第二个 AsyncTask 没有执行


- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01