实时轨迹数据排队问题

一个标准的异步消息处理线程应该怎么写?
方法1:

class LooperThread extends Thread {
public Handler mHandler;

public void run() {
Looper.prepare();
mHandler = new Handler() {
public void handleMessage(Message msg) {
// process incoming messages here
}
};
Looper.loop();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
方法2:

// Step 1: 创建并启动HandlerThread线程,内部包含Looper
HandlerThread handlerThread = new HandlerThread("gityuan.com");
handlerThread.start(http://www.amjmh.com/v/);

// Step 2: 创建Handler
Handler handler = new Handler(handlerThread.getLooper()) {
public void handleMessage(Message msg) {
// process incoming messages here
}
};
// Step 3: 发送消息
handler.post(new Runnable() {
@Override
public void run() {
System.out.println("thread id="+Thread.currentThread().getId());
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
上面就是Android系统中异步消息处理线程的通用写法

原文地址:https://www.cnblogs.com/ly570/p/11369963.html