Real-time trace data queuing problem

A standard asynchronous message processing thread should be how to write?
method 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
above it is the general system Android written asynchronous message processing threads

Guess you like

Origin www.cnblogs.com/ly570/p/11369963.html