|
1
|
package com.crossoverjie.cim.common.data.construct;
|
1
|
package com.crossoverjie.cim.common.data.construct;
|
|
2
|
|
2
|
|
|
3
|
-import org.junit.Test;
|
|
|
|
4
|
import org.slf4j.Logger;
|
3
|
import org.slf4j.Logger;
|
|
5
|
import org.slf4j.LoggerFactory;
|
4
|
import org.slf4j.LoggerFactory;
|
|
6
|
|
5
|
|
|
@@ -13,7 +12,7 @@ public class RingBufferWheelTest { |
|
@@ -13,7 +12,7 @@ public class RingBufferWheelTest { |
|
13
|
private static Logger logger = LoggerFactory.getLogger(RingBufferWheelTest.class) ;
|
12
|
private static Logger logger = LoggerFactory.getLogger(RingBufferWheelTest.class) ;
|
|
14
|
|
13
|
|
|
15
|
public static void main(String[] args) throws InterruptedException {
|
14
|
public static void main(String[] args) throws InterruptedException {
|
|
16
|
- test5();
|
15
|
+ test1();
|
|
17
|
|
16
|
|
|
18
|
return;
|
17
|
return;
|
|
19
|
}
|
18
|
}
|
|
@@ -30,8 +29,6 @@ public class RingBufferWheelTest { |
|
@@ -30,8 +29,6 @@ public class RingBufferWheelTest { |
|
30
|
task.setKey(74);
|
29
|
task.setKey(74);
|
|
31
|
wheel.addTask(task) ;
|
30
|
wheel.addTask(task) ;
|
|
32
|
|
31
|
|
|
33
|
- wheel.start();
|
|
|
|
34
|
-
|
|
|
|
35
|
while (true){
|
32
|
while (true){
|
|
36
|
logger.info("task size={}" , wheel.taskSize());
|
33
|
logger.info("task size={}" , wheel.taskSize());
|
|
37
|
TimeUnit.SECONDS.sleep(1);
|
34
|
TimeUnit.SECONDS.sleep(1);
|
|
@@ -117,8 +114,6 @@ public class RingBufferWheelTest { |
|
@@ -117,8 +114,6 @@ public class RingBufferWheelTest { |
|
117
|
wheel.addTask(task);
|
114
|
wheel.addTask(task);
|
|
118
|
}
|
115
|
}
|
|
119
|
|
116
|
|
|
120
|
- wheel.start();
|
|
|
|
121
|
-
|
|
|
|
122
|
logger.info("task size={}",wheel.taskSize());
|
117
|
logger.info("task size={}",wheel.taskSize());
|
|
123
|
|
118
|
|
|
124
|
wheel.stop(false);
|
119
|
wheel.stop(false);
|
|
@@ -134,6 +129,32 @@ public class RingBufferWheelTest { |
|
@@ -134,6 +129,32 @@ public class RingBufferWheelTest { |
|
134
|
logger.info("================");
|
129
|
logger.info("================");
|
|
135
|
}
|
130
|
}
|
|
136
|
}
|
131
|
}
|
|
|
|
132
|
+ private static void cuncrrentTest6() throws InterruptedException {
|
|
|
|
133
|
+ ExecutorService executorService = Executors.newFixedThreadPool(10) ;
|
|
|
|
134
|
+
|
|
|
|
135
|
+ RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
|
|
|
136
|
+
|
|
|
|
137
|
+ for (int i = 0; i < 10; i++) {
|
|
|
|
138
|
+
|
|
|
|
139
|
+ RingBufferWheel.Task task = new Job(i) ;
|
|
|
|
140
|
+ task.setKey(i);
|
|
|
|
141
|
+ wheel.addTask(task);
|
|
|
|
142
|
+ }
|
|
|
|
143
|
+
|
|
|
|
144
|
+ wheel.start();
|
|
|
|
145
|
+
|
|
|
|
146
|
+ TimeUnit.SECONDS.sleep(10);
|
|
|
|
147
|
+ RingBufferWheel.Task task = new Job(15) ;
|
|
|
|
148
|
+ task.setKey(15);
|
|
|
|
149
|
+ wheel.addTask(task);
|
|
|
|
150
|
+ wheel.start();
|
|
|
|
151
|
+
|
|
|
|
152
|
+ logger.info("task size={}",wheel.taskSize());
|
|
|
|
153
|
+
|
|
|
|
154
|
+ wheel.stop(false);
|
|
|
|
155
|
+
|
|
|
|
156
|
+
|
|
|
|
157
|
+ }
|
|
137
|
|
158
|
|
|
138
|
private static class Job extends RingBufferWheel.Task{
|
159
|
private static class Job extends RingBufferWheel.Task{
|
|
139
|
|
160
|
|