【发布时间】:2015-03-10 01:00:55
【问题描述】:
考虑以下 sn-p:
Looper.prepare();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
getLooper().quitSafely();
}
};
for(int i = 0; i < urls.size(); i++) {
useCaseProvider.get().execute(callback, handler, urls.get(i), threadPool);
}
Looper.loop();
//Continue processing the results of all the use cases after the
//loop has been asked to terminated via the handler
一点背景知识:我正在 UI 线程上进行一些处理,我需要 ping 大量设备并对结果进行处理。我需要并行执行请求以提高效率。
问题:如果其中一个用例以某种方式执行得足够快并在我能够点击 Looper.loop() 之前进行了回调;消息会排队还是丢失?回调正在通过将可运行对象发布到原始线程的处理程序发送回此线程。
【问题讨论】: