|
1
|
package com.crossoverjie.cim.common.data.construct;
|
1
|
package com.crossoverjie.cim.common.data.construct;
|
|
2
|
|
2
|
|
|
|
|
3
|
+
|
|
3
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
4
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
|
5
|
+
|
|
4
|
import org.slf4j.Logger;
|
6
|
import org.slf4j.Logger;
|
|
5
|
import org.slf4j.LoggerFactory;
|
7
|
import org.slf4j.LoggerFactory;
|
|
6
|
|
8
|
|
|
@@ -17,7 +19,7 @@ public class RingBufferWheelTest { |
|
@@ -17,7 +19,7 @@ public class RingBufferWheelTest { |
|
17
|
private static Logger logger = LoggerFactory.getLogger(RingBufferWheelTest.class) ;
|
19
|
private static Logger logger = LoggerFactory.getLogger(RingBufferWheelTest.class) ;
|
|
18
|
|
20
|
|
|
19
|
public static void main(String[] args) throws InterruptedException {
|
21
|
public static void main(String[] args) throws InterruptedException {
|
|
20
|
- test1();
|
22
|
+ test5();
|
|
21
|
|
23
|
|
|
22
|
return;
|
24
|
return;
|
|
23
|
}
|
25
|
}
|
|
@@ -25,7 +27,7 @@ public class RingBufferWheelTest { |
|
@@ -25,7 +27,7 @@ public class RingBufferWheelTest { |
|
25
|
private static void test1() throws InterruptedException {
|
27
|
private static void test1() throws InterruptedException {
|
|
26
|
ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
28
|
ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
|
27
|
|
29
|
|
|
28
|
- Task task = new Task() ;
|
30
|
+ RingBufferWheel.Task task = new Task() ;
|
|
29
|
task.setKey(10);
|
31
|
task.setKey(10);
|
|
30
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
32
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
|
31
|
wheel.addTask(task) ;
|
33
|
wheel.addTask(task) ;
|
|
@@ -42,7 +44,7 @@ public class RingBufferWheelTest { |
|
@@ -42,7 +44,7 @@ public class RingBufferWheelTest { |
|
42
|
private static void test2() throws InterruptedException {
|
44
|
private static void test2() throws InterruptedException {
|
|
43
|
ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
45
|
ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
|
44
|
|
46
|
|
|
45
|
- Task task = new Task() ;
|
47
|
+ RingBufferWheel.Task task = new Task() ;
|
|
46
|
task.setKey(10);
|
48
|
task.setKey(10);
|
|
47
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
49
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
|
48
|
wheel.addTask(task) ;
|
50
|
wheel.addTask(task) ;
|
|
@@ -72,7 +74,7 @@ public class RingBufferWheelTest { |
|
@@ -72,7 +74,7 @@ public class RingBufferWheelTest { |
|
72
|
private static void test3() throws InterruptedException {
|
74
|
private static void test3() throws InterruptedException {
|
|
73
|
ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
75
|
ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
|
74
|
|
76
|
|
|
75
|
- Task task = new Task() ;
|
77
|
+ RingBufferWheel.Task task = new Task() ;
|
|
76
|
task.setKey(10);
|
78
|
task.setKey(10);
|
|
77
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
79
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
|
78
|
wheel.addTask(task) ;
|
80
|
wheel.addTask(task) ;
|
|
@@ -95,7 +97,7 @@ public class RingBufferWheelTest { |
|
@@ -95,7 +97,7 @@ public class RingBufferWheelTest { |
|
95
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
97
|
RingBufferWheel wheel = new RingBufferWheel(executorService) ;
|
|
96
|
|
98
|
|
|
97
|
for (int i = 0; i < 65; i++) {
|
99
|
for (int i = 0; i < 65; i++) {
|
|
98
|
- Job task = new Job(i) ;
|
100
|
+ RingBufferWheel.Task task = new Job(i) ;
|
|
99
|
task.setKey(i);
|
101
|
task.setKey(i);
|
|
100
|
wheel.addTask(task);
|
102
|
wheel.addTask(task);
|
|
101
|
}
|
103
|
}
|
|
@@ -114,7 +116,7 @@ public class RingBufferWheelTest { |
|
@@ -114,7 +116,7 @@ public class RingBufferWheelTest { |
|
114
|
RingBufferWheel wheel = new RingBufferWheel(executorService,512) ;
|
116
|
RingBufferWheel wheel = new RingBufferWheel(executorService,512) ;
|
|
115
|
|
117
|
|
|
116
|
for (int i = 0; i < 65; i++) {
|
118
|
for (int i = 0; i < 65; i++) {
|
|
117
|
- Job task = new Job(i) ;
|
119
|
+ RingBufferWheel.Task task = new Job(i) ;
|
|
118
|
task.setKey(i);
|
120
|
task.setKey(i);
|
|
119
|
wheel.addTask(task);
|
121
|
wheel.addTask(task);
|
|
120
|
}
|
122
|
}
|
|
@@ -125,14 +127,28 @@ public class RingBufferWheelTest { |
|
@@ -125,14 +127,28 @@ public class RingBufferWheelTest { |
|
125
|
|
127
|
|
|
126
|
|
128
|
|
|
127
|
}
|
129
|
}
|
|
|
|
130
|
+ private static void test6() throws InterruptedException {
|
|
|
|
131
|
+ ExecutorService executorService = Executors.newFixedThreadPool(2) ;
|
|
128
|
|
132
|
|
|
|
|
133
|
+ RingBufferWheel wheel = new RingBufferWheel(executorService,512) ;
|
|
129
|
|
134
|
|
|
130
|
- private static class Task extends RingBufferWheel.Task{
|
|
|
|
131
|
-
|
|
|
|
132
|
- @Override
|
|
|
|
133
|
- public void run() {
|
|
|
|
134
|
- logger.info("================");
|
135
|
+ for (int i = 0; i < 10; i++) {
|
|
|
|
136
|
+ RingBufferWheel.Task task = new Job(i) ;
|
|
|
|
137
|
+ task.setKey(i);
|
|
|
|
138
|
+ wheel.addTask(task);
|
|
135
|
}
|
139
|
}
|
|
|
|
140
|
+
|
|
|
|
141
|
+
|
|
|
|
142
|
+ TimeUnit.SECONDS.sleep(10);
|
|
|
|
143
|
+ RingBufferWheel.Task task = new Job(15) ;
|
|
|
|
144
|
+ task.setKey(15);
|
|
|
|
145
|
+ wheel.addTask(task);
|
|
|
|
146
|
+
|
|
|
|
147
|
+ logger.info("task size={}",wheel.taskSize());
|
|
|
|
148
|
+
|
|
|
|
149
|
+ wheel.stop(false);
|
|
|
|
150
|
+
|
|
|
|
151
|
+
|
|
136
|
}
|
152
|
}
|
|
137
|
private static void cuncrrentTest6() throws InterruptedException {
|
153
|
private static void cuncrrentTest6() throws InterruptedException {
|
|
138
|
BlockingQueue<Runnable> queue = new LinkedBlockingQueue(10);
|
154
|
BlockingQueue<Runnable> queue = new LinkedBlockingQueue(10);
|
|
@@ -184,4 +200,13 @@ public class RingBufferWheelTest { |
|
@@ -184,4 +200,13 @@ public class RingBufferWheelTest { |
|
184
|
logger.info("number={}" , num);
|
200
|
logger.info("number={}" , num);
|
|
185
|
}
|
201
|
}
|
|
186
|
}
|
202
|
}
|
|
|
|
203
|
+
|
|
|
|
204
|
+ private static class Task extends RingBufferWheel.Task{
|
|
|
|
205
|
+
|
|
|
|
206
|
+ @Override
|
|
|
|
207
|
+ public void run() {
|
|
|
|
208
|
+ logger.info("================");
|
|
|
|
209
|
+ }
|
|
|
|
210
|
+
|
|
|
|
211
|
+ }
|
|
187
|
} |
212
|
} |