-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDSMain.java
More file actions
56 lines (40 loc) · 1.27 KB
/
Copy pathDSMain.java
File metadata and controls
56 lines (40 loc) · 1.27 KB
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
48
49
50
51
52
53
54
55
56
package disruptor;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;
import java.nio.ByteBuffer;
import java.util.concurrent.ThreadFactory;
/**
* <B>主类名称:</B>Main<BR>
* <B>概要说明:</B>第一个ds小程序<BR>
* @author
*/
public class DSMain {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
int ringBufferSize = 1024 * 1024;
OrderEventFactory orderEventFactory = new OrderEventFactory();
Disruptor<OrderEvent> disruptor = new Disruptor<>(orderEventFactory,
ringBufferSize,
new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r);
thread.setName("ds-thread");
return thread;
}
},
ProducerType.SINGLE, new BlockingWaitStrategy());
disruptor.handleEventsWith(new OrderEventHandler());
disruptor.start();
RingBuffer<OrderEvent> ringBuffer = disruptor.getRingBuffer();
OrderEventProducer producer = new OrderEventProducer(ringBuffer);
ByteBuffer bb = ByteBuffer.allocate(8);
for(long i = 0 ; i < 100; i++) {
bb.putLong(0, i);
producer.putData(bb);
}
disruptor.shutdown();
}
}