生产环境Message分发处理设计
# handleMessage
HandlerPoster

public boolean handleMessage(Message msg) {
boolean rescheduled = false;
// todo
}
1
2
3
4
2
3
4
上述 queue 的定义如下
# PendingPostQueue
final class PendingPostQueue {
@Nullable
private PendingPost head;
@Nullable
private PendingPost tail;
PendingPostQueue() {
}
synchronized void enqueue(PendingPost pendingPost) {
if (pendingPost == null) {
} else {
if (this.tail != null) {
this.tail.next = pendingPost;
this.tail = pendingPost;
} else {
if (this.head != null) {
return;
}
this.head = this.tail = pendingPost;
}
this.notifyAll();
}
}
synchronized PendingPost poll() {
PendingPost pendingPost = this.head;
if (this.head != null) {
this.head = this.head.next;
if (this.head == null) {
this.tail = null;
}
}
return pendingPost;
}
synchronized PendingPost poll(int maxMillisToWait) throws InterruptedException {
if (this.head == null) {
this.wait((long)maxMillisToWait);
}
return this.poll();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
上次更新: 2025/10/09, 23:53:03