|
@@ -45,6 +45,13 @@ public final class RingBufferWheel { |
|
@@ -45,6 +45,13 @@ public final class RingBufferWheel { |
|
45
|
*/
|
45
|
*/
|
|
46
|
private volatile boolean stop = false;
|
46
|
private volatile boolean stop = false;
|
|
47
|
|
47
|
|
|
|
|
48
|
+ private volatile boolean start = false ;
|
|
|
|
49
|
+
|
|
|
|
50
|
+ /**
|
|
|
|
51
|
+ * total tick times
|
|
|
|
52
|
+ */
|
|
|
|
53
|
+ private AtomicInteger tick = new AtomicInteger() ;
|
|
|
|
54
|
+
|
|
48
|
private Lock lock = new ReentrantLock();
|
55
|
private Lock lock = new ReentrantLock();
|
|
49
|
private Condition condition = lock.newCondition();
|
56
|
private Condition condition = lock.newCondition();
|
|
50
|
|
57
|
|
|
@@ -112,10 +119,15 @@ public final class RingBufferWheel { |
|
@@ -112,10 +119,15 @@ public final class RingBufferWheel { |
|
112
|
* Start background thread to consumer wheel timer, it will always run until you call method {@link #stop}
|
119
|
* Start background thread to consumer wheel timer, it will always run until you call method {@link #stop}
|
|
113
|
*/
|
120
|
*/
|
|
114
|
public void start() {
|
121
|
public void start() {
|
|
|
|
122
|
+
|
|
|
|
123
|
+ if (!start){
|
|
115
|
logger.info("delay task is starting");
|
124
|
logger.info("delay task is starting");
|
|
116
|
Thread job = new Thread(new TriggerJob());
|
125
|
Thread job = new Thread(new TriggerJob());
|
|
117
|
job.setName("consumer RingBuffer thread");
|
126
|
job.setName("consumer RingBuffer thread");
|
|
118
|
job.start();
|
127
|
job.start();
|
|
|
|
128
|
+ start = true ;
|
|
|
|
129
|
+ }
|
|
|
|
130
|
+
|
|
119
|
}
|
131
|
}
|
|
120
|
|
132
|
|
|
121
|
/**
|
133
|
/**
|
|
@@ -211,6 +223,7 @@ public final class RingBufferWheel { |
|
@@ -211,6 +223,7 @@ public final class RingBufferWheel { |
|
211
|
|
223
|
|
|
212
|
private int mod(int target, int mod) {
|
224
|
private int mod(int target, int mod) {
|
|
213
|
// equals target % mod
|
225
|
// equals target % mod
|
|
|
|
226
|
+ target = target + tick.get() ;
|
|
214
|
return target & (mod - 1);
|
227
|
return target & (mod - 1);
|
|
215
|
}
|
228
|
}
|
|
216
|
|
229
|
|
|
@@ -267,6 +280,8 @@ public final class RingBufferWheel { |
|
@@ -267,6 +280,8 @@ public final class RingBufferWheel { |
|
267
|
index = 0;
|
280
|
index = 0;
|
|
268
|
}
|
281
|
}
|
|
269
|
|
282
|
|
|
|
|
283
|
+ //Total tick number of records
|
|
|
|
284
|
+ tick.incrementAndGet();
|
|
270
|
try {
|
285
|
try {
|
|
271
|
TimeUnit.SECONDS.sleep(1);
|
286
|
TimeUnit.SECONDS.sleep(1);
|
|
272
|
} catch (InterruptedException e) {
|
287
|
} catch (InterruptedException e) {
|