File tree Expand file tree Collapse file tree 3 files changed +13
-22
lines changed Expand file tree Collapse file tree 3 files changed +13
-22
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 7070
7171接收端能够从消息队列成功消费一次消息。
7272
73- 实现方法 :
73+ 两种实现方法 :
7474
7575- 保证接收端处理消息的业务逻辑具有幂等性:只要具有幂等性,那么消费多少次消息,最后处理的结果都是一样的。
7676- 保证消息具有唯一编号,并使用一张日志表来记录已经消费的消息编号。
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ public class LRU<K, V> implements Iterable<K> {
5858 }
5959 }
6060
61+
6162 public LRU (int maxSize ) {
6263
6364 this . maxSize = maxSize;
@@ -70,6 +71,7 @@ public class LRU<K, V> implements Iterable<K> {
7071 tail. pre = head;
7172 }
7273
74+
7375 public V get (K key ) {
7476
7577 if (! map. containsKey(key)) {
@@ -83,6 +85,7 @@ public class LRU<K, V> implements Iterable<K> {
8385 return node. v;
8486 }
8587
88+
8689 public void put (K key , V value ) {
8790
8891 if (map. containsKey(key)) {
@@ -100,30 +103,34 @@ public class LRU<K, V> implements Iterable<K> {
100103 }
101104 }
102105
106+
103107 private void unlink (Node node ) {
104108 Node pre = node. pre;
105- node. pre = node. next;
106- node. next = pre;
109+ Node next = node. next;
110+ pre. next = next;
111+ next. pre = pre;
107112 }
108113
114+
109115 private void appendHead (Node node ) {
110116 node. next = head. next;
117+ node. pre = head;
111118 head. next = node;
112119 }
113120
121+
114122 private Node removeTail () {
115123 Node node = tail. pre;
116- node . pre = tail ;
124+ tail . pre = node . pre ;
117125 return node;
118126 }
119127
128+
120129 @Override
121130 public Iterator<K > iterator () {
122131
123132 return new Iterator<K > () {
124-
125133 private Node cur = head. next;
126-
127134 @Override
128135 public boolean hasNext () {
129136 return cur != tail;
You can’t perform that action at this time.
0 commit comments